diff --git a/pkg/core/account_state.go b/pkg/core/account_state.go index 7c14151d7..f2779340c 100644 --- a/pkg/core/account_state.go +++ b/pkg/core/account_state.go @@ -77,6 +77,9 @@ type UnspentBalance struct { Value util.Fixed8 `json:"value"` } +// UnspentBalances is a slice of UnspentBalance (mostly needed to sort them). +type UnspentBalances []UnspentBalance + // AccountState represents the state of a NEO account. type AccountState struct { Version uint8 @@ -156,3 +159,12 @@ func (s *AccountState) GetBalanceValues() map[util.Uint256]util.Fixed8 { } return res } + +// Len returns the length of UnspentBalances (used to sort things). +func (us UnspentBalances) Len() int { return len(us) } + +// Less compares two elements of UnspentBalances (used to sort things). +func (us UnspentBalances) Less(i, j int) bool { return us[i].Value < us[j].Value } + +// Swap swaps two elements of UnspentBalances (used to sort things). +func (us UnspentBalances) Swap(i, j int) { us[i], us[j] = us[j], us[i] } diff --git a/pkg/rpc/neoScanBalanceGetter.go b/pkg/rpc/neoScanBalanceGetter.go index c51fba304..50d6fb289 100644 --- a/pkg/rpc/neoScanBalanceGetter.go +++ b/pkg/rpc/neoScanBalanceGetter.go @@ -36,7 +36,6 @@ func (s NeoScanServer) GetBalance(address string) ([]*Unspent, error) { if err = json.NewDecoder(res.Body).Decode(&balance); err != nil { return nil, errs.Wrap(err, "Failed to decode HTTP response") } - return balance.Balance, nil } @@ -82,8 +81,8 @@ func (s NeoScanServer) CalculateInputs(address string, assetIDUint util.Uint256, inputs := make([]transaction.Input, 0, num) for i = 0; i < num; i++ { inputs = append(inputs, transaction.Input{ - PrevHash: assetUnspent.Unspent[i].TxID, - PrevIndex: assetUnspent.Unspent[i].N, + PrevHash: assetUnspent.Unspent[i].Tx, + PrevIndex: assetUnspent.Unspent[i].Index, }) } diff --git a/pkg/rpc/neoScanTypes.go b/pkg/rpc/neoScanTypes.go index 9ef6a81b1..bafd0b648 100644 --- a/pkg/rpc/neoScanTypes.go +++ b/pkg/rpc/neoScanTypes.go @@ -1,6 +1,9 @@ package rpc -import "github.com/CityOfZion/neo-go/pkg/util" +import ( + "github.com/CityOfZion/neo-go/pkg/core" + "github.com/CityOfZion/neo-go/pkg/util" +) /* Definition of types, helper functions and variables @@ -15,19 +18,9 @@ type ( Path string // path to API endpoint without wallet address } - // UTXO stores unspent TX output for some transaction. - UTXO struct { - Value util.Fixed8 - TxID util.Uint256 - N uint16 - } - - // Unspents is a slice of UTXOs (TODO: drop it?). - Unspents []UTXO - // Unspent stores Unspents per asset Unspent struct { - Unspent Unspents + Unspent core.UnspentBalances Asset string // "NEO" / "GAS" Amount util.Fixed8 // total unspent of this asset } @@ -38,8 +31,3 @@ type ( Address string } ) - -// functions for sorting array of `Unspents` -func (us Unspents) Len() int { return len(us) } -func (us Unspents) Less(i, j int) bool { return us[i].Value < us[j].Value } -func (us Unspents) Swap(i, j int) { us[i], us[j] = us[j], us[i] }