Merge pull request #340 from nspcc-dev/fix-golint-213
Make our build green again! Fixes #213.
This commit is contained in:
commit
e636537844
56 changed files with 180 additions and 112 deletions
|
@ -194,6 +194,7 @@ func testInvoke(ctx *cli.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ContractDetails contains contract metadata.
|
||||||
type ContractDetails struct {
|
type ContractDetails struct {
|
||||||
Author string
|
Author string
|
||||||
Email string
|
Email string
|
||||||
|
|
|
@ -15,10 +15,13 @@ import (
|
||||||
const (
|
const (
|
||||||
userAgentFormat = "/NEO-GO:%s/"
|
userAgentFormat = "/NEO-GO:%s/"
|
||||||
|
|
||||||
// Valid NetMode constants.
|
// ModeMainNet contains magic code used in the NEO main official network.
|
||||||
ModeMainNet NetMode = 0x00746e41 // 7630401
|
ModeMainNet NetMode = 0x00746e41 // 7630401
|
||||||
|
// ModeTestNet contains magic code used in the NEO testing network.
|
||||||
ModeTestNet NetMode = 0x74746e41 // 1953787457
|
ModeTestNet NetMode = 0x74746e41 // 1953787457
|
||||||
|
// ModePrivNet contains magic code usually used for NEO private networks.
|
||||||
ModePrivNet NetMode = 56753 // docker privnet
|
ModePrivNet NetMode = 56753 // docker privnet
|
||||||
|
// ModeUnitTestNet is a stub magic code used for testing purposes.
|
||||||
ModeUnitTestNet NetMode = 0
|
ModeUnitTestNet NetMode = 0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -91,8 +94,8 @@ func (c Config) GenerateUserAgent() string {
|
||||||
return fmt.Sprintf(userAgentFormat, Version)
|
return fmt.Sprintf(userAgentFormat, Version)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loadattempts to load the config from the give
|
// Load attempts to load the config from the given
|
||||||
// path and netMode.
|
// path for the given netMode.
|
||||||
func Load(path string, netMode NetMode) (Config, error) {
|
func Load(path string, netMode NetMode) (Config, error) {
|
||||||
configPath := fmt.Sprintf("%s/protocol.%s.yml", path, netMode)
|
configPath := fmt.Sprintf("%s/protocol.%s.yml", path, netMode)
|
||||||
if _, err := os.Stat(configPath); os.IsNotExist(err) {
|
if _, err := os.Stat(configPath); os.IsNotExist(err) {
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
package engine_contract
|
package enginecontract
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/CityOfZion/neo-go/pkg/interop/engine"
|
"github.com/CityOfZion/neo-go/pkg/interop/engine"
|
||||||
"github.com/CityOfZion/neo-go/pkg/interop/runtime"
|
"github.com/CityOfZion/neo-go/pkg/interop/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Main is that famous Main() function, you know.
|
||||||
func Main() bool {
|
func Main() bool {
|
||||||
tx := engine.GetScriptContainer()
|
tx := engine.GetScriptContainer()
|
||||||
runtime.Notify(tx)
|
runtime.Notify(tx)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package iterator_contract
|
package iteratorcontract
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/CityOfZion/neo-go/pkg/interop/iterator"
|
"github.com/CityOfZion/neo-go/pkg/interop/iterator"
|
||||||
|
@ -6,6 +6,7 @@ import (
|
||||||
"github.com/CityOfZion/neo-go/pkg/interop/storage"
|
"github.com/CityOfZion/neo-go/pkg/interop/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Main is Main(), really.
|
||||||
func Main() bool {
|
func Main() bool {
|
||||||
iter := storage.Find(storage.GetContext(), []byte("foo"))
|
iter := storage.Find(storage.GetContext(), []byte("foo"))
|
||||||
values := iterator.Values(iter)
|
values := iterator.Values(iter)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package runtime_contract
|
package runtimecontract
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/CityOfZion/neo-go/pkg/interop/runtime"
|
"github.com/CityOfZion/neo-go/pkg/interop/runtime"
|
||||||
|
@ -8,6 +8,7 @@ import (
|
||||||
// Check if the invoker of the contract is the specified owner
|
// Check if the invoker of the contract is the specified owner
|
||||||
var owner = util.FromAddress("Aej1fe4mUgou48Zzup5j8sPrE3973cJ5oz")
|
var owner = util.FromAddress("Aej1fe4mUgou48Zzup5j8sPrE3973cJ5oz")
|
||||||
|
|
||||||
|
// Main is something to be ran from outside.
|
||||||
func Main(operation string, args []interface{}) bool {
|
func Main(operation string, args []interface{}) bool {
|
||||||
trigger := runtime.GetTrigger()
|
trigger := runtime.GetTrigger()
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package storage_contract
|
package storagecontract
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/CityOfZion/neo-go/pkg/interop/storage"
|
"github.com/CityOfZion/neo-go/pkg/interop/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Main is a very useful function.
|
||||||
func Main(operation string, args []interface{}) interface{} {
|
func Main(operation string, args []interface{}) interface{} {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package token_contract
|
package tokencontract
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/CityOfZion/neo-go/examples/token/nep5"
|
"github.com/CityOfZion/neo-go/examples/token/nep5"
|
||||||
|
|
|
@ -83,7 +83,7 @@ func NewBlockchain(ctx context.Context, s storage.Store, cfg config.ProtocolConf
|
||||||
return bc, nil
|
return bc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBlockchainLevelDB returns blockchain based on configuration
|
// NewBlockchainLevelDB initializes new blockchain DB store based on configuration
|
||||||
func NewBlockchainLevelDB(ctx context.Context, cfg config.Config) (*Blockchain, error) {
|
func NewBlockchainLevelDB(ctx context.Context, cfg config.Config) (*Blockchain, error) {
|
||||||
store, err := storage.NewLevelDBStore(
|
store, err := storage.NewLevelDBStore(
|
||||||
ctx,
|
ctx,
|
||||||
|
@ -502,6 +502,7 @@ func (bc *Blockchain) GetBlock(hash util.Uint256) (*Block, error) {
|
||||||
return block, nil
|
return block, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetHeader returns data block header identified with the given hash value.
|
||||||
func (bc *Blockchain) GetHeader(hash util.Uint256) (*Header, error) {
|
func (bc *Blockchain) GetHeader(hash util.Uint256) (*Header, error) {
|
||||||
b, err := bc.Get(storage.AppendPrefix(storage.DataBlock, hash.BytesReverse()))
|
b, err := bc.Get(storage.AppendPrefix(storage.DataBlock, hash.BytesReverse()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -790,43 +791,41 @@ func (bc *Blockchain) GetTransationResults(t *transaction.Transaction) []*transa
|
||||||
var results []*transaction.Result
|
var results []*transaction.Result
|
||||||
tempGroupResult := make(map[util.Uint256]util.Fixed8)
|
tempGroupResult := make(map[util.Uint256]util.Fixed8)
|
||||||
|
|
||||||
if references := bc.References(t); references == nil {
|
references := bc.References(t)
|
||||||
|
if references == nil {
|
||||||
return nil
|
return nil
|
||||||
} else {
|
}
|
||||||
for _, output := range references {
|
for _, output := range references {
|
||||||
tempResults = append(tempResults, &transaction.Result{
|
tempResults = append(tempResults, &transaction.Result{
|
||||||
AssetID: output.AssetID,
|
AssetID: output.AssetID,
|
||||||
Amount: output.Amount,
|
Amount: output.Amount,
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
for _, output := range t.Outputs {
|
||||||
|
tempResults = append(tempResults, &transaction.Result{
|
||||||
|
AssetID: output.AssetID,
|
||||||
|
Amount: -output.Amount,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
for _, r := range tempResults {
|
||||||
|
if amount, ok := tempGroupResult[r.AssetID]; ok {
|
||||||
|
tempGroupResult[r.AssetID] = amount.Add(r.Amount)
|
||||||
|
} else {
|
||||||
|
tempGroupResult[r.AssetID] = r.Amount
|
||||||
}
|
}
|
||||||
for _, output := range t.Outputs {
|
|
||||||
tempResults = append(tempResults, &transaction.Result{
|
|
||||||
AssetID: output.AssetID,
|
|
||||||
Amount: -output.Amount,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
for _, r := range tempResults {
|
|
||||||
if amount, ok := tempGroupResult[r.AssetID]; ok {
|
|
||||||
tempGroupResult[r.AssetID] = amount.Add(r.Amount)
|
|
||||||
} else {
|
|
||||||
tempGroupResult[r.AssetID] = r.Amount
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
results = []*transaction.Result{} // this assignment is necessary. (Most of the time amount == 0 and results is the empty slice.)
|
|
||||||
for assetID, amount := range tempGroupResult {
|
|
||||||
if amount != util.Fixed8(0) {
|
|
||||||
results = append(results, &transaction.Result{
|
|
||||||
AssetID: assetID,
|
|
||||||
Amount: amount,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return results
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
results = []*transaction.Result{} // this assignment is necessary. (Most of the time amount == 0 and results is the empty slice.)
|
||||||
|
for assetID, amount := range tempGroupResult {
|
||||||
|
if amount != util.Fixed8(0) {
|
||||||
|
results = append(results, &transaction.Result{
|
||||||
|
AssetID: assetID,
|
||||||
|
Amount: amount,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetScriptHashesForVerifying returns all the ScriptHashes of a transaction which will be use
|
// GetScriptHashesForVerifying returns all the ScriptHashes of a transaction which will be use
|
||||||
|
|
|
@ -86,7 +86,6 @@ func TestGetHeader(t *testing.T) {
|
||||||
assert.Equal(t, block.Header(), header)
|
assert.Equal(t, block.Header(), header)
|
||||||
|
|
||||||
block = newBlock(2)
|
block = newBlock(2)
|
||||||
hash = block.Hash()
|
|
||||||
_, err = bc.GetHeader(block.Hash())
|
_, err = bc.GetHeader(block.Hash())
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ func (attr *Attribute) EncodeBinary(w io.Writer) error {
|
||||||
Remark12, Remark13, Remark14, Remark15:
|
Remark12, Remark13, Remark14, Remark15:
|
||||||
bw.WriteBytes(attr.Data)
|
bw.WriteBytes(attr.Data)
|
||||||
case DescriptionURL:
|
case DescriptionURL:
|
||||||
var urllen uint8 = uint8(len(attr.Data))
|
var urllen = uint8(len(attr.Data))
|
||||||
bw.WriteLE(urllen)
|
bw.WriteLE(urllen)
|
||||||
fallthrough
|
fallthrough
|
||||||
case Script, ContractHash, Vote, Hash1, Hash2, Hash3, Hash4, Hash5, Hash6,
|
case Script, ContractHash, Vote, Hash1, Hash2, Hash3, Hash4, Hash5, Hash6,
|
||||||
|
|
|
@ -43,6 +43,7 @@ func (tx *ClaimTX) EncodeBinary(w io.Writer) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Size returns serialized binary size for this transaction.
|
||||||
func (tx *ClaimTX) Size() int {
|
func (tx *ClaimTX) Size() int {
|
||||||
sz := util.GetVarSize(uint64(len(tx.Claims)))
|
sz := util.GetVarSize(uint64(len(tx.Claims)))
|
||||||
for _, claim := range tx.Claims {
|
for _, claim := range tx.Claims {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
// This TX has not special attributes.
|
// This TX has not special attributes.
|
||||||
type ContractTX struct{}
|
type ContractTX struct{}
|
||||||
|
|
||||||
|
// NewContractTX creates Transaction of ContractType type.
|
||||||
func NewContractTX() *Transaction {
|
func NewContractTX() *Transaction {
|
||||||
return &Transaction{
|
return &Transaction{
|
||||||
Type: ContractType,
|
Type: ContractType,
|
||||||
|
@ -24,6 +25,7 @@ func (tx *ContractTX) EncodeBinary(w io.Writer) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Size returns serialized binary size for this transaction.
|
||||||
func (tx *ContractTX) Size() int {
|
func (tx *ContractTX) Size() int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"github.com/CityOfZion/neo-go/pkg/crypto/keys"
|
"github.com/CityOfZion/neo-go/pkg/crypto/keys"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A Enrollment transaction represents an enrollment form, which indicates
|
// EnrollmentTX transaction represents an enrollment form, which indicates
|
||||||
// that the sponsor of the transaction would like to sign up as a validator.
|
// that the sponsor of the transaction would like to sign up as a validator.
|
||||||
// The way to sign up is: To construct an EnrollmentTransaction type of transaction,
|
// The way to sign up is: To construct an EnrollmentTransaction type of transaction,
|
||||||
// and send a deposit to the address of the PublicKey.
|
// and send a deposit to the address of the PublicKey.
|
||||||
|
@ -27,6 +27,7 @@ func (tx *EnrollmentTX) EncodeBinary(w io.Writer) error {
|
||||||
return tx.PublicKey.EncodeBinary(w)
|
return tx.PublicKey.EncodeBinary(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Size returns serialized binary size for this transaction.
|
||||||
func (tx *EnrollmentTX) Size() int {
|
func (tx *EnrollmentTX) Size() int {
|
||||||
return len(tx.PublicKey.Bytes())
|
return len(tx.PublicKey.Bytes())
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,7 @@ func (tx *InvocationTX) EncodeBinary(w io.Writer) error {
|
||||||
return bw.Err
|
return bw.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Size returns serialized binary size for this transaction.
|
||||||
func (tx *InvocationTX) Size() int {
|
func (tx *InvocationTX) Size() int {
|
||||||
sz := util.GetVarSize(tx.Script)
|
sz := util.GetVarSize(tx.Script)
|
||||||
if (tx.Version >= 1) {
|
if (tx.Version >= 1) {
|
||||||
|
|
|
@ -18,6 +18,7 @@ func (tx *IssueTX) EncodeBinary(w io.Writer) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Size returns serialized binary size for this transaction.
|
||||||
func (tx *IssueTX) Size() int {
|
func (tx *IssueTX) Size() int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ func (tx *MinerTX) EncodeBinary(w io.Writer) error {
|
||||||
return binary.Write(w, binary.LittleEndian, tx.Nonce)
|
return binary.Write(w, binary.LittleEndian, tx.Nonce)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Size returns serialized binary size for this transaction.
|
||||||
func (tx *MinerTX) Size() int {
|
func (tx *MinerTX) Size() int {
|
||||||
return 4 // Nonce
|
return 4 // Nonce
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,12 +74,13 @@ func (tx *PublishTX) EncodeBinary(w io.Writer) error {
|
||||||
return bw.Err
|
return bw.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Size returns serialized binary size for this transaction.
|
||||||
func (tx *PublishTX) Size() int {
|
func (tx *PublishTX) Size() int {
|
||||||
sz := util.GetVarSize(tx.Script) + util.GetVarSize(uint64(len(tx.ParamList)))
|
sz := util.GetVarSize(tx.Script) + util.GetVarSize(uint64(len(tx.ParamList)))
|
||||||
sz += 1 * len(tx.ParamList)
|
sz += 1 * len(tx.ParamList)
|
||||||
sz += 1
|
sz++
|
||||||
if tx.Version >= 1 {
|
if tx.Version >= 1 {
|
||||||
sz += 1
|
sz++
|
||||||
}
|
}
|
||||||
sz += util.GetVarSize(tx.Name) + util.GetVarSize(tx.CodeVersion)
|
sz += util.GetVarSize(tx.Name) + util.GetVarSize(tx.CodeVersion)
|
||||||
sz += util.GetVarSize(tx.Author) + util.GetVarSize(tx.Email)
|
sz += util.GetVarSize(tx.Author) + util.GetVarSize(tx.Email)
|
||||||
|
|
|
@ -63,6 +63,7 @@ func (tx *RegisterTX) EncodeBinary(w io.Writer) error {
|
||||||
return bw.Err
|
return bw.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Size returns serialized binary size for this transaction.
|
||||||
func (tx *RegisterTX) Size() int {
|
func (tx *RegisterTX) Size() int {
|
||||||
return 1 + util.GetVarSize(tx.Name) + tx.Amount.Size() + 1 + len(tx.Owner.Bytes()) + tx.Admin.Size()
|
return 1 + util.GetVarSize(tx.Name) + tx.Amount.Size() + 1 + len(tx.Owner.Bytes()) + tx.Admin.Size()
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ func (tx *StateTX) EncodeBinary(w io.Writer) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Size returns serialized binary size for this transaction.
|
||||||
func (tx *StateTX) Size() int {
|
func (tx *StateTX) Size() int {
|
||||||
sz := util.GetVarSize(uint64(len(tx.Descriptors)))
|
sz := util.GetVarSize(uint64(len(tx.Descriptors)))
|
||||||
for _, desc := range tx.Descriptors {
|
for _, desc := range tx.Descriptors {
|
||||||
|
|
|
@ -45,6 +45,7 @@ func (s *StateDescriptor) EncodeBinary(w io.Writer) error {
|
||||||
return bw.Err
|
return bw.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Size returns serialized binary size for state descriptor.
|
||||||
func (s *StateDescriptor) Size() int {
|
func (s *StateDescriptor) Size() int {
|
||||||
return 1 + util.GetVarSize(s.Key) + util.GetVarSize(s.Value) + util.GetVarSize(s.Field)
|
return 1 + util.GetVarSize(s.Key) + util.GetVarSize(s.Value) + util.GetVarSize(s.Field)
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,7 +251,7 @@ func (t *Transaction) createHash() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GroupTXInputsByPrevHash groups all TX inputs by their previous hash.
|
// GroupInputsByPrevHash groups all TX inputs by their previous hash.
|
||||||
func (t *Transaction) GroupInputsByPrevHash() map[util.Uint256][]*Input {
|
func (t *Transaction) GroupInputsByPrevHash() map[util.Uint256][]*Input {
|
||||||
m := make(map[util.Uint256][]*Input)
|
m := make(map[util.Uint256][]*Input)
|
||||||
for _, in := range t.Inputs {
|
for _, in := range t.Inputs {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package transaction
|
||||||
// TXType is the type of a transaction.
|
// TXType is the type of a transaction.
|
||||||
type TXType uint8
|
type TXType uint8
|
||||||
|
|
||||||
|
// Constants for all valid transaction types.
|
||||||
const (
|
const (
|
||||||
MinerType TXType = 0x00
|
MinerType TXType = 0x00
|
||||||
IssueType TXType = 0x01
|
IssueType TXType = 0x01
|
||||||
|
|
|
@ -96,11 +96,11 @@ func Base58CheckDecode(s string) (b []byte, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(b) < 5 {
|
if len(b) < 5 {
|
||||||
return nil, errors.New("invalid base-58 check string: missing checksum.")
|
return nil, errors.New("invalid base-58 check string: missing checksum")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.Equal(hash.Checksum(b[:len(b)-4]), b[len(b)-4:]) {
|
if !bytes.Equal(hash.Checksum(b[:len(b)-4]), b[len(b)-4:]) {
|
||||||
return nil, errors.New("invalid base-58 check string: invalid checksum.")
|
return nil, errors.New("invalid base-58 check string: invalid checksum")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Strip the 4 byte long hash.
|
// Strip the 4 byte long hash.
|
||||||
|
@ -109,7 +109,7 @@ func Base58CheckDecode(s string) (b []byte, err error) {
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Base58checkEncode encodes b into a base-58 check encoded string.
|
// Base58CheckEncode encodes b into a base-58 check encoded string.
|
||||||
func Base58CheckEncode(b []byte) string {
|
func Base58CheckEncode(b []byte) string {
|
||||||
b = append(b, hash.Checksum(b)...)
|
b = append(b, hash.Checksum(b)...)
|
||||||
|
|
||||||
|
|
|
@ -24,12 +24,14 @@ const (
|
||||||
|
|
||||||
var nepHeader = []byte{0x01, 0x42}
|
var nepHeader = []byte{0x01, 0x42}
|
||||||
|
|
||||||
|
// ScryptParams is a json-serializable container for scrypt KDF parameters.
|
||||||
type ScryptParams struct {
|
type ScryptParams struct {
|
||||||
N int `json:"n"`
|
N int `json:"n"`
|
||||||
R int `json:"r"`
|
R int `json:"r"`
|
||||||
P int `json:"p"`
|
P int `json:"p"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NEP2ScryptParams returns scrypt parameters specified in the NEP-2.
|
||||||
func NEP2ScryptParams() ScryptParams {
|
func NEP2ScryptParams() ScryptParams {
|
||||||
return ScryptParams{
|
return ScryptParams{
|
||||||
N: n,
|
N: n,
|
||||||
|
|
|
@ -22,6 +22,7 @@ type PrivateKey struct {
|
||||||
b []byte
|
b []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewPrivateKey creates a new random private key.
|
||||||
func NewPrivateKey() (*PrivateKey, error) {
|
func NewPrivateKey() (*PrivateKey, error) {
|
||||||
c := crypto.NewEllipticCurve()
|
c := crypto.NewEllipticCurve()
|
||||||
b := make([]byte, c.N.BitLen()/8+8)
|
b := make([]byte, c.N.BitLen()/8+8)
|
||||||
|
|
|
@ -168,6 +168,7 @@ func (p *PublicKey) EncodeBinary(w io.Writer) error {
|
||||||
return binary.Write(w, binary.LittleEndian, p.Bytes())
|
return binary.Write(w, binary.LittleEndian, p.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Signature returns a NEO-specific hash of the key.
|
||||||
func (p *PublicKey) Signature() []byte {
|
func (p *PublicKey) Signature() []byte {
|
||||||
b := p.Bytes()
|
b := p.Bytes()
|
||||||
b = append([]byte{0x21}, b...)
|
b = append([]byte{0x21}, b...)
|
||||||
|
@ -178,8 +179,9 @@ func (p *PublicKey) Signature() []byte {
|
||||||
return sig.Bytes()
|
return sig.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Address returns a base58-encoded NEO-specific address based on the key hash.
|
||||||
func (p *PublicKey) Address() string {
|
func (p *PublicKey) Address() string {
|
||||||
var b []byte = p.Signature()
|
var b = p.Signature()
|
||||||
|
|
||||||
b = append([]byte{0x17}, b...)
|
b = append([]byte{0x17}, b...)
|
||||||
csum := hash.Checksum(b)
|
csum := hash.Checksum(b)
|
||||||
|
|
|
@ -91,6 +91,7 @@ func WIFDecode(wif string, version byte) (*WIF, error) {
|
||||||
return w, nil
|
return w, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetVerificationScript returns NEO VM bytecode with checksig command for the public key.
|
||||||
func (wif WIF) GetVerificationScript() ([]byte, error) {
|
func (wif WIF) GetVerificationScript() ([]byte, error) {
|
||||||
const (
|
const (
|
||||||
pushbytes33 = 0x21
|
pushbytes33 = 0x21
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// MerkleTree implementation.
|
// MerkleTree implementation.
|
||||||
|
|
||||||
type MerkleTree struct {
|
type MerkleTree struct {
|
||||||
root *MerkleTreeNode
|
root *MerkleTreeNode
|
||||||
depth int
|
depth int
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package keytestcases
|
package keytestcases
|
||||||
|
|
||||||
|
// Ktype represents key testcase values (different encodings of the key).
|
||||||
type Ktype struct {
|
type Ktype struct {
|
||||||
Address,
|
Address,
|
||||||
PrivateKey,
|
PrivateKey,
|
||||||
|
@ -9,6 +10,7 @@ type Ktype struct {
|
||||||
EncryptedWif string
|
EncryptedWif string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Arr contains a set of known keys in Ktype format.
|
||||||
var Arr = []Ktype{
|
var Arr = []Ktype{
|
||||||
{
|
{
|
||||||
Address: "ALq7AWrhAueN6mJNqk6FHJjnsEoPRytLdW",
|
Address: "ALq7AWrhAueN6mJNqk6FHJjnsEoPRytLdW",
|
||||||
|
|
|
@ -6,7 +6,7 @@ package account
|
||||||
// Account stubs a NEO account type.
|
// Account stubs a NEO account type.
|
||||||
type Account struct{}
|
type Account struct{}
|
||||||
|
|
||||||
// GetScripHash returns the script hash of the given account.
|
// GetScriptHash returns the script hash of the given account.
|
||||||
func GetScriptHash(a Account) []byte {
|
func GetScriptHash(a Account) []byte {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,5 +49,5 @@ func GetIssuer(a Asset) []byte {
|
||||||
// Create registers a new asset on the blockchain.
|
// Create registers a new asset on the blockchain.
|
||||||
func Create(assetType byte, name string, amount int, precision byte, owner, admin, issuer []byte) {}
|
func Create(assetType byte, name string, amount int, precision byte, owner, admin, issuer []byte) {}
|
||||||
|
|
||||||
// Renew renews the existance of an asset by the given years.
|
// Renew renews the existence of an asset by the given years.
|
||||||
func Renew(asset Asset, years int) {}
|
func Renew(asset Asset, years int) {}
|
||||||
|
|
|
@ -11,8 +11,8 @@ func Create(items []interface{}) Iterator {
|
||||||
return Iterator{}
|
return Iterator{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Better description for this.
|
|
||||||
// Key returns the iterator key.
|
// Key returns the iterator key.
|
||||||
|
// TODO: Better description for this.
|
||||||
func Key(it Iterator) interface{} {
|
func Key(it Iterator) interface{} {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,14 +27,14 @@ func GetAttributes(t Transaction) []attribute.Attribute {
|
||||||
return []attribute.Attribute{}
|
return []attribute.Attribute{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: What is the correct return type for this?
|
|
||||||
// GetReferences returns a slice of references for the given transaction.
|
// GetReferences returns a slice of references for the given transaction.
|
||||||
|
// FIXME: What is the correct return type for this?
|
||||||
func GetReferences(t Transaction) []interface{} {
|
func GetReferences(t Transaction) []interface{} {
|
||||||
return []interface{}{}
|
return []interface{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: What is the correct return type for this?
|
|
||||||
// GetUnspentCoins returns the unspent coins for the given transaction.
|
// GetUnspentCoins returns the unspent coins for the given transaction.
|
||||||
|
// FIXME: What is the correct return type for this?
|
||||||
func GetUnspentCoins(t Transaction) interface{} {
|
func GetUnspentCoins(t Transaction) interface{} {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/CityOfZion/neo-go/pkg/util"
|
"github.com/CityOfZion/neo-go/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// MerkleBlock represents a merkle block packet payload.
|
||||||
type MerkleBlock struct {
|
type MerkleBlock struct {
|
||||||
*core.BlockBase
|
*core.BlockBase
|
||||||
TxCount int
|
TxCount int
|
||||||
|
@ -14,6 +15,7 @@ type MerkleBlock struct {
|
||||||
Flags []byte
|
Flags []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DecodeBinary implements the Payload interface.
|
||||||
func (m *MerkleBlock) DecodeBinary(r io.Reader) error {
|
func (m *MerkleBlock) DecodeBinary(r io.Reader) error {
|
||||||
m.BlockBase = &core.BlockBase{}
|
m.BlockBase = &core.BlockBase{}
|
||||||
if err := m.BlockBase.DecodeBinary(r); err != nil {
|
if err := m.BlockBase.DecodeBinary(r); err != nil {
|
||||||
|
@ -31,6 +33,7 @@ func (m *MerkleBlock) DecodeBinary(r io.Reader) error {
|
||||||
return br.Err
|
return br.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EncodeBinary implements the Payload interface.
|
||||||
func (m *MerkleBlock) EncodeBinary(w io.Writer) error {
|
func (m *MerkleBlock) EncodeBinary(w io.Writer) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ func TestVersionEncodeDecode(t *testing.T) {
|
||||||
var id uint32 = 13337
|
var id uint32 = 13337
|
||||||
useragent := "/NEO:0.0.1/"
|
useragent := "/NEO:0.0.1/"
|
||||||
var height uint32 = 100500
|
var height uint32 = 100500
|
||||||
var relay bool = true
|
var relay = true
|
||||||
|
|
||||||
version := NewVersion(id, port, useragent, height, relay)
|
version := NewVersion(id, port, useragent, height, relay)
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"github.com/CityOfZion/neo-go/pkg/util"
|
"github.com/CityOfZion/neo-go/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Peer represents a network node neo-go is connected to.
|
||||||
type Peer interface {
|
type Peer interface {
|
||||||
Endpoint() util.Endpoint
|
Endpoint() util.Endpoint
|
||||||
Disconnect(error)
|
Disconnect(error)
|
||||||
|
|
|
@ -23,6 +23,7 @@ type TCPPeer struct {
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewTCPPeer returns a TCPPeer structure based on the given connection.
|
||||||
func NewTCPPeer(conn net.Conn) *TCPPeer {
|
func NewTCPPeer(conn net.Conn) *TCPPeer {
|
||||||
return &TCPPeer{
|
return &TCPPeer{
|
||||||
conn: conn,
|
conn: conn,
|
||||||
|
|
|
@ -93,6 +93,7 @@ func NewClient(ctx context.Context, endpoint string, opts ClientOptions) (*Clien
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WIF returns WIF structure associated with the client.
|
||||||
func (c *Client) WIF() keys.WIF {
|
func (c *Client) WIF() keys.WIF {
|
||||||
c.wifMu.Lock()
|
c.wifMu.Lock()
|
||||||
defer c.wifMu.Unlock()
|
defer c.wifMu.Unlock()
|
||||||
|
@ -117,12 +118,14 @@ func (c *Client) SetWIF(wif string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Balancer is a getter for balance field.
|
||||||
func (c *Client) Balancer() BalanceGetter {
|
func (c *Client) Balancer() BalanceGetter {
|
||||||
c.balancerMu.Lock()
|
c.balancerMu.Lock()
|
||||||
defer c.balancerMu.Unlock()
|
defer c.balancerMu.Unlock()
|
||||||
return c.balancer
|
return c.balancer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetBalancer is a setter for balance field.
|
||||||
func (c *Client) SetBalancer(b BalanceGetter) {
|
func (c *Client) SetBalancer(b BalanceGetter) {
|
||||||
c.balancerMu.Lock()
|
c.balancerMu.Lock()
|
||||||
defer c.balancerMu.Unlock()
|
defer c.balancerMu.Unlock()
|
||||||
|
@ -132,12 +135,14 @@ func (c *Client) SetBalancer(b BalanceGetter) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Client is a getter for client field.
|
||||||
func (c *Client) Client() *http.Client {
|
func (c *Client) Client() *http.Client {
|
||||||
c.cliMu.Lock()
|
c.cliMu.Lock()
|
||||||
defer c.cliMu.Unlock()
|
defer c.cliMu.Unlock()
|
||||||
return c.cli
|
return c.cli
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetClient is a setter for client field.
|
||||||
func (c *Client) SetClient(cli *http.Client) {
|
func (c *Client) SetClient(cli *http.Client) {
|
||||||
c.cliMu.Lock()
|
c.cliMu.Lock()
|
||||||
defer c.cliMu.Unlock()
|
defer c.cliMu.Unlock()
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
errs "github.com/pkg/errors"
|
errs "github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GetBalance performs a request to get balance for the address specified.
|
||||||
func (s NeoScanServer) GetBalance(address string) ([]*Unspent, error) {
|
func (s NeoScanServer) GetBalance(address string) ([]*Unspent, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
|
@ -49,7 +50,8 @@ func filterSpecificAsset(asset string, balance []*Unspent, assetBalance *Unspent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s NeoScanServer) CalculateInputs(address string, assetIdUint util.Uint256, cost util.Fixed8) ([]transaction.Input, util.Fixed8, error) {
|
// CalculateInputs creates input transactions for the specified amount of given asset belonging to specified address.
|
||||||
|
func (s NeoScanServer) CalculateInputs(address string, assetIDUint util.Uint256, cost util.Fixed8) ([]transaction.Input, util.Fixed8, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
num, i uint16
|
num, i uint16
|
||||||
|
@ -57,12 +59,12 @@ func (s NeoScanServer) CalculateInputs(address string, assetIdUint util.Uint256,
|
||||||
selected = util.Fixed8(0)
|
selected = util.Fixed8(0)
|
||||||
us []*Unspent
|
us []*Unspent
|
||||||
assetUnspent Unspent
|
assetUnspent Unspent
|
||||||
assetId = GlobalAssets[assetIdUint.ReverseString()]
|
assetID = GlobalAssets[assetIDUint.ReverseString()]
|
||||||
)
|
)
|
||||||
if us, err = s.GetBalance(address); err != nil {
|
if us, err = s.GetBalance(address); err != nil {
|
||||||
return nil, util.Fixed8(0), errs.Wrapf(err, "Cannot get balance for address %v", address)
|
return nil, util.Fixed8(0), errs.Wrapf(err, "Cannot get balance for address %v", address)
|
||||||
}
|
}
|
||||||
filterSpecificAsset(assetId, us, &assetUnspent)
|
filterSpecificAsset(assetID, us, &assetUnspent)
|
||||||
sort.Sort(assetUnspent.Unspent)
|
sort.Sort(assetUnspent.Unspent)
|
||||||
|
|
||||||
for _, us := range assetUnspent.Unspent {
|
for _, us := range assetUnspent.Unspent {
|
||||||
|
|
|
@ -9,35 +9,37 @@ import "github.com/CityOfZion/neo-go/pkg/util"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
// NeoScanServer stores NEOSCAN URL and API path
|
||||||
NeoScanServer struct {
|
NeoScanServer struct {
|
||||||
URL string // "protocol://host:port/"
|
URL string // "protocol://host:port/"
|
||||||
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 {
|
UTXO struct {
|
||||||
Value util.Fixed8
|
Value util.Fixed8
|
||||||
TxID util.Uint256
|
TxID util.Uint256
|
||||||
N uint16
|
N uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unspents is a slice of UTXOs (TODO: drop it?).
|
||||||
Unspents []UTXO
|
Unspents []UTXO
|
||||||
|
|
||||||
// unspent per asset
|
// Unspent stores Unspents per asset
|
||||||
Unspent struct {
|
Unspent struct {
|
||||||
Unspent Unspents
|
Unspent Unspents
|
||||||
Asset string // "NEO" / "GAS"
|
Asset string // "NEO" / "GAS"
|
||||||
Amount util.Fixed8 // total unspent of this asset
|
Amount util.Fixed8 // total unspent of this asset
|
||||||
}
|
}
|
||||||
|
|
||||||
// struct of NeoScan response to 'get_balance' request
|
// NeoScanBalance is a struct of NeoScan response to 'get_balance' request
|
||||||
NeoScanBalance struct {
|
NeoScanBalance struct {
|
||||||
Balance []*Unspent
|
Balance []*Unspent
|
||||||
Address string
|
Address string
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// NeoScan returns asset IDs as strings ("NEO"/"GAS");
|
// GlobalAssets stores a map of asset IDs to user-friendly strings ("NEO"/"GAS");
|
||||||
// strings might be converted to uint256 assets IDs using this map
|
|
||||||
var GlobalAssets = map[string]string{
|
var GlobalAssets = map[string]string{
|
||||||
"c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b": "NEO",
|
"c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b": "NEO",
|
||||||
"602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7": "GAS",
|
"602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7": "GAS",
|
||||||
|
|
|
@ -10,21 +10,22 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetBlock returns a block by its hash or index/height. If verbose is true
|
// getBlock returns a block by its hash or index/height. If verbose is true
|
||||||
// the response will contain a pretty Block object instead of the raw hex string.
|
// the response will contain a pretty Block object instead of the raw hex string.
|
||||||
func (c *Client) GetBlock(indexOrHash interface{}, verbose bool) (*response, error) {
|
// missing output wrapper at the moment, thus commented out
|
||||||
var (
|
// func (c *Client) getBlock(indexOrHash interface{}, verbose bool) (*response, error) {
|
||||||
params = newParams(indexOrHash)
|
// var (
|
||||||
resp = &response{}
|
// params = newParams(indexOrHash)
|
||||||
)
|
// resp = &response{}
|
||||||
if verbose {
|
// )
|
||||||
params = newParams(indexOrHash, 1)
|
// if verbose {
|
||||||
}
|
// params = newParams(indexOrHash, 1)
|
||||||
if err := c.performRequest("getblock", params, resp); err != nil {
|
// }
|
||||||
return nil, err
|
// if err := c.performRequest("getblock", params, resp); err != nil {
|
||||||
}
|
// return nil, err
|
||||||
return resp, nil
|
// }
|
||||||
}
|
// return resp, nil
|
||||||
|
// }
|
||||||
|
|
||||||
// GetAccountState will return detailed information about a NEO account.
|
// GetAccountState will return detailed information about a NEO account.
|
||||||
func (c *Client) GetAccountState(address string) (*AccountStateResponse, error) {
|
func (c *Client) GetAccountState(address string) (*AccountStateResponse, error) {
|
||||||
|
@ -65,7 +66,7 @@ func (c *Client) InvokeFunction(script, operation string, params []smartcontract
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// InvokeFunction return the results after calling a the smart contract scripthash
|
// Invoke returns the results after calling a the smart contract scripthash
|
||||||
// with the given parameters.
|
// with the given parameters.
|
||||||
func (c *Client) Invoke(script string, params []smartcontract.Parameter) (*InvokeScriptResponse, error) {
|
func (c *Client) Invoke(script string, params []smartcontract.Parameter) (*InvokeScriptResponse, error) {
|
||||||
var (
|
var (
|
||||||
|
@ -78,23 +79,24 @@ func (c *Client) Invoke(script string, params []smartcontract.Parameter) (*Invok
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRawTransaction queries a transaction by hash.
|
// getRawTransaction queries a transaction by hash.
|
||||||
func (c *Client) GetRawTransaction(hash string, verbose bool) (*response, error) {
|
// missing output wrapper at the moment, thus commented out
|
||||||
var (
|
// func (c *Client) getRawTransaction(hash string, verbose bool) (*response, error) {
|
||||||
params = newParams(hash, verbose)
|
// var (
|
||||||
resp = &response{}
|
// params = newParams(hash, verbose)
|
||||||
)
|
// resp = &response{}
|
||||||
if err := c.performRequest("getrawtransaction", params, resp); err != nil {
|
// )
|
||||||
return nil, err
|
// if err := c.performRequest("getrawtransaction", params, resp); err != nil {
|
||||||
}
|
// return nil, err
|
||||||
return resp, nil
|
// }
|
||||||
}
|
// return resp, nil
|
||||||
|
// }
|
||||||
|
|
||||||
// SendRawTransaction broadcasts a transaction over the NEO network.
|
// sendRawTransaction broadcasts a transaction over the NEO network.
|
||||||
// The given hex string needs to be signed with a keypair.
|
// The given hex string needs to be signed with a keypair.
|
||||||
// When the result of the response object is true, the TX has successfully
|
// When the result of the response object is true, the TX has successfully
|
||||||
// been broadcasted to the network.
|
// been broadcasted to the network.
|
||||||
func (c *Client) SendRawTransaction(rawTX string) (*response, error) {
|
func (c *Client) sendRawTransaction(rawTX string) (*response, error) {
|
||||||
var (
|
var (
|
||||||
params = newParams(rawTX)
|
params = newParams(rawTX)
|
||||||
resp = &response{}
|
resp = &response{}
|
||||||
|
@ -115,7 +117,7 @@ func (c *Client) SendToAddress(asset util.Uint256, address string, amount util.F
|
||||||
rawTx *transaction.Transaction
|
rawTx *transaction.Transaction
|
||||||
rawTxStr string
|
rawTxStr string
|
||||||
txParams = ContractTxParams{
|
txParams = ContractTxParams{
|
||||||
assetId: asset,
|
assetID: asset,
|
||||||
address: address,
|
address: address,
|
||||||
value: amount,
|
value: amount,
|
||||||
wif: c.WIF(),
|
wif: c.WIF(),
|
||||||
|
@ -132,7 +134,7 @@ func (c *Client) SendToAddress(asset util.Uint256, address string, amount util.F
|
||||||
return nil, errors.Wrap(err, "failed to encode raw transaction to binary for `sendtoaddress`")
|
return nil, errors.Wrap(err, "failed to encode raw transaction to binary for `sendtoaddress`")
|
||||||
}
|
}
|
||||||
rawTxStr = hex.EncodeToString(buf.Bytes())
|
rawTxStr = hex.EncodeToString(buf.Bytes())
|
||||||
if resp, err = c.SendRawTransaction(rawTxStr); err != nil {
|
if resp, err = c.sendRawTransaction(rawTxStr); err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to send raw transaction")
|
return nil, errors.Wrap(err, "failed to send raw transaction")
|
||||||
}
|
}
|
||||||
response.Error = resp.Error
|
response.Error = resp.Error
|
||||||
|
|
|
@ -24,18 +24,18 @@ type tc struct {
|
||||||
expectedResult string
|
expectedResult string
|
||||||
}
|
}
|
||||||
|
|
||||||
var testRpcCases = []tc{
|
var testRPCCases = []tc{
|
||||||
|
|
||||||
{
|
{
|
||||||
rpcCall: `{"jsonrpc": "2.0", "id": 1, "method": "getassetstate", "params": ["602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7"] }`,
|
rpcCall: `{"jsonrpc": "2.0", "id": 1, "method": "getassetstate", "params": ["602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7"] }`,
|
||||||
method: "getassetstate_1",
|
method: "getassetstate_1",
|
||||||
expectedResult: `{"jsonrpc":"2.0","result":{"assetId":"0x602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7","assetType":1,"name":"NEOGas","amount":"100000000","available":"0","precision":8,"fee":0,"address":"0x0000000000000000000000000000000000000000","owner":"00","admin":"AWKECj9RD8rS8RPcpCgYVjk1DeYyHwxZm3","issuer":"AFmseVrdL9f9oyCzZefL9tG6UbvhPbdYzM","expiration":0,"is_frozen":false},"id":1}`,
|
expectedResult: `{"jsonrpc":"2.0","result":{"assetID":"0x602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7","assetType":1,"name":"NEOGas","amount":"100000000","available":"0","precision":8,"fee":0,"address":"0x0000000000000000000000000000000000000000","owner":"00","admin":"AWKECj9RD8rS8RPcpCgYVjk1DeYyHwxZm3","issuer":"AFmseVrdL9f9oyCzZefL9tG6UbvhPbdYzM","expiration":0,"is_frozen":false},"id":1}`,
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
rpcCall: `{ "jsonrpc": "2.0", "id": 1, "method": "getassetstate", "params": ["c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b"] }`,
|
rpcCall: `{ "jsonrpc": "2.0", "id": 1, "method": "getassetstate", "params": ["c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b"] }`,
|
||||||
method: "getassetstate_2",
|
method: "getassetstate_2",
|
||||||
expectedResult: `{"jsonrpc":"2.0","result":{"assetId":"0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b","assetType":0,"name":"NEO","amount":"100000000","available":"0","precision":0,"fee":0,"address":"0x0000000000000000000000000000000000000000","owner":"00","admin":"Abf2qMs1pzQb8kYk9RuxtUb9jtRKJVuBJt","issuer":"AFmseVrdL9f9oyCzZefL9tG6UbvhPbdYzM","expiration":0,"is_frozen":false},"id":1}`,
|
expectedResult: `{"jsonrpc":"2.0","result":{"assetID":"0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b","assetType":0,"name":"NEO","amount":"100000000","available":"0","precision":0,"fee":0,"address":"0x0000000000000000000000000000000000000000","owner":"00","admin":"Abf2qMs1pzQb8kYk9RuxtUb9jtRKJVuBJt","issuer":"AFmseVrdL9f9oyCzZefL9tG6UbvhPbdYzM","expiration":0,"is_frozen":false},"id":1}`,
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -255,13 +255,13 @@ func TestHandler(t *testing.T) {
|
||||||
// setup handler
|
// setup handler
|
||||||
handler := http.HandlerFunc(rpcServer.requestHandler)
|
handler := http.HandlerFunc(rpcServer.requestHandler)
|
||||||
|
|
||||||
testRpcCases = append(testRpcCases, tc{
|
testRPCCases = append(testRPCCases, tc{
|
||||||
rpcCall: `{"jsonrpc": "2.0", "id": 1, "method": "getversion", "params": [] }`,
|
rpcCall: `{"jsonrpc": "2.0", "id": 1, "method": "getversion", "params": [] }`,
|
||||||
method: "getversion",
|
method: "getversion",
|
||||||
expectedResult: fmt.Sprintf(`{"jsonrpc":"2.0","result":{"port":20333,"nonce":%s,"useragent":"/NEO-GO:/"},"id":1}`, strconv.FormatUint(uint64(server.ID()), 10)),
|
expectedResult: fmt.Sprintf(`{"jsonrpc":"2.0","result":{"port":20333,"nonce":%s,"useragent":"/NEO-GO:/"},"id":1}`, strconv.FormatUint(uint64(server.ID()), 10)),
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, tc := range testRpcCases {
|
for _, tc := range testRPCCases {
|
||||||
t.Run(fmt.Sprintf("method: %s, rpc call: %s", tc.method, tc.rpcCall), func(t *testing.T) {
|
t.Run(fmt.Sprintf("method: %s, rpc call: %s", tc.method, tc.rpcCall), func(t *testing.T) {
|
||||||
|
|
||||||
req := httptest.NewRequest("POST", "http://0.0.0.0:20333/", strings.NewReader(tc.rpcCall))
|
req := httptest.NewRequest("POST", "http://0.0.0.0:20333/", strings.NewReader(tc.rpcCall))
|
||||||
|
|
|
@ -10,8 +10,10 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// StackParamType represents different types of stack values.
|
||||||
type StackParamType int
|
type StackParamType int
|
||||||
|
|
||||||
|
// All possible StackParamType values are listed here
|
||||||
const (
|
const (
|
||||||
Unknown StackParamType = -1
|
Unknown StackParamType = -1
|
||||||
Signature StackParamType = 0x00
|
Signature StackParamType = 0x00
|
||||||
|
@ -27,6 +29,7 @@ const (
|
||||||
Void StackParamType = 0xff
|
Void StackParamType = 0xff
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// String implements the stringer interface.
|
||||||
func (t StackParamType) String() string {
|
func (t StackParamType) String() string {
|
||||||
switch t {
|
switch t {
|
||||||
case Signature:
|
case Signature:
|
||||||
|
@ -56,6 +59,7 @@ func (t StackParamType) String() string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StackParamTypeFromString converts string into the StackParamType.
|
||||||
func StackParamTypeFromString(s string) (StackParamType, error) {
|
func StackParamTypeFromString(s string) (StackParamType, error) {
|
||||||
switch s {
|
switch s {
|
||||||
case "Signature":
|
case "Signature":
|
||||||
|
@ -85,6 +89,7 @@ func StackParamTypeFromString(s string) (StackParamType, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON sets StackParamType from JSON-encoded data.
|
||||||
func (t *StackParamType) UnmarshalJSON(data []byte) (err error) {
|
func (t *StackParamType) UnmarshalJSON(data []byte) (err error) {
|
||||||
var (
|
var (
|
||||||
s = string(data)
|
s = string(data)
|
||||||
|
@ -174,8 +179,10 @@ func (p *StackParam) UnmarshalJSON(data []byte) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StackParams in an array of StackParam (TODO: drop it?).
|
||||||
type StackParams []StackParam
|
type StackParams []StackParam
|
||||||
|
|
||||||
|
// TryParseArray converts an array of StackParam into an array of more appropriate things.
|
||||||
func (p StackParams) TryParseArray(vals ...interface{}) error {
|
func (p StackParams) TryParseArray(vals ...interface{}) error {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
|
@ -193,6 +200,7 @@ func (p StackParams) TryParseArray(vals ...interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TryParse converts one StackParam into something more appropriate.
|
||||||
func (p StackParam) TryParse(dest interface{}) error {
|
func (p StackParam) TryParse(dest interface{}) error {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
errs "github.com/pkg/errors"
|
errs "github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// CreateRawContractTransaction returns contract-type Transaction built from specified parameters.
|
||||||
func CreateRawContractTransaction(params ContractTxParams) (*transaction.Transaction, error) {
|
func CreateRawContractTransaction(params ContractTxParams) (*transaction.Transaction, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
|
@ -21,7 +22,7 @@ func CreateRawContractTransaction(params ContractTxParams) (*transaction.Transac
|
||||||
spent util.Fixed8
|
spent util.Fixed8
|
||||||
witness transaction.Witness
|
witness transaction.Witness
|
||||||
|
|
||||||
wif, assetID, address, amount, balancer = params.wif, params.assetId, params.address, params.value, params.balancer
|
wif, assetID, address, amount, balancer = params.wif, params.assetID, params.address, params.value, params.balancer
|
||||||
)
|
)
|
||||||
|
|
||||||
if fromAddress, err = wif.PrivateKey.Address(); err != nil {
|
if fromAddress, err = wif.PrivateKey.Address(); err != nil {
|
||||||
|
@ -67,6 +68,7 @@ func CreateRawContractTransaction(params ContractTxParams) (*transaction.Transac
|
||||||
return tx, nil
|
return tx, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetInvocationScript returns NEO VM script containing transaction signature.
|
||||||
func GetInvocationScript(tx *transaction.Transaction, wif keys.WIF) ([]byte, error) {
|
func GetInvocationScript(tx *transaction.Transaction, wif keys.WIF) ([]byte, error) {
|
||||||
const (
|
const (
|
||||||
pushbytes64 = 0x40
|
pushbytes64 = 0x40
|
||||||
|
|
|
@ -12,11 +12,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// parameters for tx to transfer assets;
|
// ContractTxParams contains parameters for tx to transfer assets;
|
||||||
// includes parameters duplication `sendtoaddress` RPC call params
|
// includes parameters duplication `sendtoaddress` RPC call params
|
||||||
// and also some utility data;
|
// and also some utility data;
|
||||||
ContractTxParams struct {
|
ContractTxParams struct {
|
||||||
assetId util.Uint256
|
assetID util.Uint256
|
||||||
address string
|
address string
|
||||||
value util.Fixed8
|
value util.Fixed8
|
||||||
wif keys.WIF // a WIF to send the transaction
|
wif keys.WIF // a WIF to send the transaction
|
||||||
|
@ -26,15 +26,16 @@ type (
|
||||||
balancer BalanceGetter
|
balancer BalanceGetter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BalanceGetter is an interface supporting CalculateInputs() method.
|
||||||
BalanceGetter interface {
|
BalanceGetter interface {
|
||||||
// parameters
|
// parameters
|
||||||
// address: base58-encoded address assets would be transferred from
|
// address: base58-encoded address assets would be transferred from
|
||||||
// assetId: asset identifier
|
// assetID: asset identifier
|
||||||
// amount: an asset amount to spend
|
// amount: an asset amount to spend
|
||||||
// return values
|
// return values
|
||||||
// inputs: UTXO's for the preparing transaction
|
// inputs: UTXO's for the preparing transaction
|
||||||
// total: summarized asset amount from all the `inputs`
|
// total: summarized asset amount from all the `inputs`
|
||||||
// error: error would be considered in the caller function
|
// error: error would be considered in the caller function
|
||||||
CalculateInputs(address string, assetId util.Uint256, amount util.Fixed8) (inputs []transaction.Input, total util.Fixed8, err error)
|
CalculateInputs(address string, assetID util.Uint256, amount util.Fixed8) (inputs []transaction.Input, total util.Fixed8, err error)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"github.com/CityOfZion/neo-go/pkg/vm"
|
"github.com/CityOfZion/neo-go/pkg/vm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// InvokeScriptResponse stores response for the invoke script call.
|
||||||
type InvokeScriptResponse struct {
|
type InvokeScriptResponse struct {
|
||||||
responseHeader
|
responseHeader
|
||||||
Error *Error `json:"error,omitempty"`
|
Error *Error `json:"error,omitempty"`
|
||||||
|
@ -73,19 +74,21 @@ type response struct {
|
||||||
Result interface{} `json:"result"`
|
Result interface{} `json:"result"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SendToAddressResponse stores response for the sendtoaddress call.
|
||||||
type SendToAddressResponse struct {
|
type SendToAddressResponse struct {
|
||||||
responseHeader
|
responseHeader
|
||||||
Error *Error `json:"error"`
|
Error *Error `json:"error"`
|
||||||
Result *TxResponse
|
Result *TxResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
// struct represents verbose output of `getrawtransaction` RPC call
|
// GetRawTxResponse struct represents verbose output of `getrawtransaction` RPC call.
|
||||||
type GetRawTxResponse struct {
|
type GetRawTxResponse struct {
|
||||||
responseHeader
|
responseHeader
|
||||||
Error *Error `json:"error"`
|
Error *Error `json:"error"`
|
||||||
Result *RawTxResponse `json:"result"`
|
Result *RawTxResponse `json:"result"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RawTxResponse stores transaction with blockchain metadata to be sent as a response.
|
||||||
type RawTxResponse struct {
|
type RawTxResponse struct {
|
||||||
TxResponse
|
TxResponse
|
||||||
BlockHash string `json:"blockhash"`
|
BlockHash string `json:"blockhash"`
|
||||||
|
@ -93,6 +96,7 @@ type RawTxResponse struct {
|
||||||
BlockTime uint `json:"blocktime"`
|
BlockTime uint `json:"blocktime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TxResponse stores transaction to be sent as a response.
|
||||||
type TxResponse struct {
|
type TxResponse struct {
|
||||||
TxID string `json:"txid"`
|
TxID string `json:"txid"`
|
||||||
Size int `json:"size"`
|
Size int `json:"size"`
|
||||||
|
@ -106,11 +110,13 @@ type TxResponse struct {
|
||||||
Scripts []transaction.Witness `json:"scripts"`
|
Scripts []transaction.Witness `json:"scripts"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Vin represents JSON-serializable tx input.
|
||||||
type Vin struct {
|
type Vin struct {
|
||||||
TxId string `json:"txid"`
|
TxID string `json:"txid"`
|
||||||
Vout int `json:"vout"`
|
Vout int `json:"vout"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Vout represents JSON-serializable tx output.
|
||||||
type Vout struct {
|
type Vout struct {
|
||||||
N int `json:"n"`
|
N int `json:"n"`
|
||||||
Asset string `json:"asset"`
|
Asset string `json:"asset"`
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
// AssetState wrapper used for the representation of
|
// AssetState wrapper used for the representation of
|
||||||
// core.AssetState on the RPC Server.
|
// core.AssetState on the RPC Server.
|
||||||
type AssetState struct {
|
type AssetState struct {
|
||||||
ID util.Uint256 `json:"assetId"`
|
ID util.Uint256 `json:"assetID"`
|
||||||
AssetType transaction.AssetType `json:"assetType"`
|
AssetType transaction.AssetType `json:"assetType"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Amount util.Fixed8 `json:"amount"`
|
Amount util.Fixed8 `json:"amount"`
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"github.com/CityOfZion/neo-go/pkg/crypto"
|
"github.com/CityOfZion/neo-go/pkg/crypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ValidateAddressResponse represents response to validate address call.
|
||||||
type ValidateAddressResponse struct {
|
type ValidateAddressResponse struct {
|
||||||
Address interface{} `json:"address"`
|
Address interface{} `json:"address"`
|
||||||
IsValid bool `json:"isvalid"`
|
IsValid bool `json:"isvalid"`
|
||||||
|
|
|
@ -51,6 +51,7 @@ func (pt ParamType) String() string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalJSON implements the json.Marshaler interface.
|
||||||
func (pt ParamType) MarshalJSON() ([]byte, error) {
|
func (pt ParamType) MarshalJSON() ([]byte, error) {
|
||||||
return []byte(`"` + pt.String() + `"`), nil
|
return []byte(`"` + pt.String() + `"`), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ func (u *Uint160) UnmarshalJSON(data []byte) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Size returns the lenght of the bytes representation of Uint160
|
// Size returns the length of the bytes representation of Uint160
|
||||||
func (u Uint160) Size() int {
|
func (u Uint160) Size() int {
|
||||||
return uint160Size
|
return uint160Size
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ func (u *Uint256) UnmarshalJSON(data []byte) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Size returns the lenght of the bytes representation of Uint256
|
// Size returns the length of the bytes representation of Uint256
|
||||||
func (u Uint256) Size() int {
|
func (u Uint256) Size() int {
|
||||||
return uint256Size
|
return uint256Size
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,6 +95,7 @@ func (i *BigIntegerItem) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(i.value)
|
return json.Marshal(i.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BoolItem represents a boolean StackItem.
|
||||||
type BoolItem struct {
|
type BoolItem struct {
|
||||||
value bool
|
value bool
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,10 +17,12 @@ const (
|
||||||
breakState
|
breakState
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// HasFlag check for State flag presence.
|
||||||
func (s State) HasFlag(f State) bool {
|
func (s State) HasFlag(f State) bool {
|
||||||
return s&f != 0
|
return s&f != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String implements the stringer interface.
|
||||||
func (s State) String() string {
|
func (s State) String() string {
|
||||||
if s == noneState {
|
if s == noneState {
|
||||||
return "NONE"
|
return "NONE"
|
||||||
|
@ -39,6 +41,7 @@ func (s State) String() string {
|
||||||
return strings.Join(ss, ", ")
|
return strings.Join(ss, ", ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StateFromString converts string into the VM State.
|
||||||
func StateFromString(s string) (st State, err error) {
|
func StateFromString(s string) (st State, err error) {
|
||||||
if s = strings.TrimSpace(s); s == "NONE" {
|
if s = strings.TrimSpace(s); s == "NONE" {
|
||||||
return noneState, nil
|
return noneState, nil
|
||||||
|
@ -60,10 +63,12 @@ func StateFromString(s string) (st State, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalJSON implements the json.Marshaler interface
|
||||||
func (s State) MarshalJSON() (data []byte, err error) {
|
func (s State) MarshalJSON() (data []byte, err error) {
|
||||||
return []byte(`"` + s.String() + `"`), nil
|
return []byte(`"` + s.String() + `"`), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON implements the json.Marshaler interface
|
||||||
func (s *State) UnmarshalJSON(data []byte) (err error) {
|
func (s *State) UnmarshalJSON(data []byte) (err error) {
|
||||||
l := len(data)
|
l := len(data)
|
||||||
if l < 2 || data[0] != '"' || data[l-1] != '"' {
|
if l < 2 || data[0] != '"' || data[l-1] != '"' {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package bar
|
package bar
|
||||||
|
|
||||||
|
// Bar is something used for testing purposes (TODO: move somewhere?)
|
||||||
type Bar struct {
|
type Bar struct {
|
||||||
X int
|
X int
|
||||||
Y int
|
Y int
|
||||||
|
|
|
@ -133,6 +133,7 @@ func (v *VM) LoadFile(path string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load initializes the VM with the program given.
|
||||||
func (v *VM) Load(prog []byte) {
|
func (v *VM) Load(prog []byte) {
|
||||||
// clear all stacks, it could be a reload.
|
// clear all stacks, it could be a reload.
|
||||||
v.istack.Clear()
|
v.istack.Clear()
|
||||||
|
|
|
@ -74,7 +74,7 @@ func newWallet(rw io.ReadWriter) *Wallet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreatAccount generates a new account for the end user and encrypts
|
// CreateAccount generates a new account for the end user and encrypts
|
||||||
// the private key with the given passphrase.
|
// the private key with the given passphrase.
|
||||||
func (w *Wallet) CreateAccount(name, passphrase string) error {
|
func (w *Wallet) CreateAccount(name, passphrase string) error {
|
||||||
acc, err := NewAccount()
|
acc, err := NewAccount()
|
||||||
|
|
Loading…
Reference in a new issue