rpc: remove duplicating definition of UTXO
Port sorting methods to core.
This commit is contained in:
parent
d2bdae99e4
commit
29882b076c
3 changed files with 19 additions and 20 deletions
|
@ -77,6 +77,9 @@ type UnspentBalance struct {
|
||||||
Value util.Fixed8 `json:"value"`
|
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.
|
// AccountState represents the state of a NEO account.
|
||||||
type AccountState struct {
|
type AccountState struct {
|
||||||
Version uint8
|
Version uint8
|
||||||
|
@ -156,3 +159,12 @@ func (s *AccountState) GetBalanceValues() map[util.Uint256]util.Fixed8 {
|
||||||
}
|
}
|
||||||
return res
|
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] }
|
||||||
|
|
|
@ -36,7 +36,6 @@ func (s NeoScanServer) GetBalance(address string) ([]*Unspent, error) {
|
||||||
if err = json.NewDecoder(res.Body).Decode(&balance); err != nil {
|
if err = json.NewDecoder(res.Body).Decode(&balance); err != nil {
|
||||||
return nil, errs.Wrap(err, "Failed to decode HTTP response")
|
return nil, errs.Wrap(err, "Failed to decode HTTP response")
|
||||||
}
|
}
|
||||||
|
|
||||||
return balance.Balance, nil
|
return balance.Balance, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,8 +81,8 @@ func (s NeoScanServer) CalculateInputs(address string, assetIDUint util.Uint256,
|
||||||
inputs := make([]transaction.Input, 0, num)
|
inputs := make([]transaction.Input, 0, num)
|
||||||
for i = 0; i < num; i++ {
|
for i = 0; i < num; i++ {
|
||||||
inputs = append(inputs, transaction.Input{
|
inputs = append(inputs, transaction.Input{
|
||||||
PrevHash: assetUnspent.Unspent[i].TxID,
|
PrevHash: assetUnspent.Unspent[i].Tx,
|
||||||
PrevIndex: assetUnspent.Unspent[i].N,
|
PrevIndex: assetUnspent.Unspent[i].Index,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package rpc
|
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
|
Definition of types, helper functions and variables
|
||||||
|
@ -15,19 +18,9 @@ type (
|
||||||
Path string // path to API endpoint without wallet address
|
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 stores Unspents per asset
|
||||||
Unspent struct {
|
Unspent struct {
|
||||||
Unspent Unspents
|
Unspent core.UnspentBalances
|
||||||
Asset string // "NEO" / "GAS"
|
Asset string // "NEO" / "GAS"
|
||||||
Amount util.Fixed8 // total unspent of this asset
|
Amount util.Fixed8 // total unspent of this asset
|
||||||
}
|
}
|
||||||
|
@ -38,8 +31,3 @@ type (
|
||||||
Address string
|
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] }
|
|
||||||
|
|
Loading…
Reference in a new issue