neoneo-go/pkg/rpc/wrappers/account_state.go
dauTT 7e43717657 Implemented rcp method GetAccountState (#124)
* Implemented rcp method GetAccountState

* code clean up

* Removed empty line

* Used consistently github.com/pkg/errors package. Amended error message

* Get rid of fmt.Sprintf and use either errors.Errorf or errors.Wrapf

* cosmetic changes
2019-02-08 09:04:38 +01:00

43 lines
1.2 KiB
Go

package wrappers
import (
"github.com/CityOfZion/neo-go/pkg/core"
"github.com/CityOfZion/neo-go/pkg/crypto"
"github.com/CityOfZion/neo-go/pkg/util"
)
// AccountState wrapper used for the representation of
// core.AccountState on the RPC Server.
type AccountState struct {
Version uint8 `json:"version"`
Address string `json:"address"`
ScriptHash util.Uint160 `json:"script_hash"`
IsFrozen bool `json:"frozen"`
Votes []*crypto.PublicKey `json:"votes"`
Balances map[string]util.Fixed8 `json:"balances"`
}
// NewAccountState creates a new AccountState wrapper.
func NewAccountState(a *core.AccountState) AccountState {
balances := make(map[string]util.Fixed8)
address := crypto.AddressFromUint160(a.ScriptHash)
for k, v := range a.Balances {
balances[k.String()] = v
}
// reverse scriptHash to be consistent with other client
scriptHash, err := util.Uint160DecodeBytes(a.ScriptHash.BytesReverse())
if err != nil {
scriptHash = a.ScriptHash
}
return AccountState{
Version: a.Version,
ScriptHash: scriptHash,
IsFrozen: a.IsFrozen,
Votes: a.Votes,
Balances: balances,
Address: address,
}
}