diff --git a/cli/smartcontract/smart_contract.go b/cli/smartcontract/smart_contract.go index 333aa01c1..4cd604e59 100644 --- a/cli/smartcontract/smart_contract.go +++ b/cli/smartcontract/smart_contract.go @@ -194,6 +194,7 @@ func testInvoke(ctx *cli.Context) error { return nil } +// ContractDetails contains contract metadata. type ContractDetails struct { Author string Email string diff --git a/config/config.go b/config/config.go index e5e856f35..6873de7d5 100644 --- a/config/config.go +++ b/config/config.go @@ -15,10 +15,13 @@ import ( const ( userAgentFormat = "/NEO-GO:%s/" - // Valid NetMode constants. + // ModeMainNet contains magic code used in the NEO main official network. ModeMainNet NetMode = 0x00746e41 // 7630401 + // ModeTestNet contains magic code used in the NEO testing network. ModeTestNet NetMode = 0x74746e41 // 1953787457 + // ModePrivNet contains magic code usually used for NEO private networks. ModePrivNet NetMode = 56753 // docker privnet + // ModeUnitTestNet is a stub magic code used for testing purposes. ModeUnitTestNet NetMode = 0 ) @@ -91,8 +94,8 @@ func (c Config) GenerateUserAgent() string { return fmt.Sprintf(userAgentFormat, Version) } -// Loadattempts to load the config from the give -// path and netMode. +// Load attempts to load the config from the given +// path for the given netMode. func Load(path string, netMode NetMode) (Config, error) { configPath := fmt.Sprintf("%s/protocol.%s.yml", path, netMode) if _, err := os.Stat(configPath); os.IsNotExist(err) { diff --git a/examples/engine/engine.go b/examples/engine/engine.go index aa210abdf..a0e5e4827 100644 --- a/examples/engine/engine.go +++ b/examples/engine/engine.go @@ -5,6 +5,7 @@ import ( "github.com/CityOfZion/neo-go/pkg/interop/runtime" ) +// Main is that famous Main() function, you know. func Main() bool { tx := engine.GetScriptContainer() runtime.Notify(tx) diff --git a/examples/iterator/iterator.go b/examples/iterator/iterator.go index 0809b173f..7398d425f 100644 --- a/examples/iterator/iterator.go +++ b/examples/iterator/iterator.go @@ -6,6 +6,7 @@ import ( "github.com/CityOfZion/neo-go/pkg/interop/storage" ) +// Main is Main(), really. func Main() bool { iter := storage.Find(storage.GetContext(), []byte("foo")) values := iterator.Values(iter) diff --git a/examples/runtime/runtime.go b/examples/runtime/runtime.go index 4d914e445..61e9c019c 100644 --- a/examples/runtime/runtime.go +++ b/examples/runtime/runtime.go @@ -8,6 +8,7 @@ import ( // Check if the invoker of the contract is the specified owner var owner = util.FromAddress("Aej1fe4mUgou48Zzup5j8sPrE3973cJ5oz") +// Main is something to be ran from outside. func Main(operation string, args []interface{}) bool { trigger := runtime.GetTrigger() diff --git a/examples/storage/storage.go b/examples/storage/storage.go index 319e9e71f..d09350e31 100644 --- a/examples/storage/storage.go +++ b/examples/storage/storage.go @@ -4,6 +4,7 @@ import ( "github.com/CityOfZion/neo-go/pkg/interop/storage" ) +// Main is a very useful function. func Main(operation string, args []interface{}) interface{} { ctx := storage.GetContext() diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index a6c0bd7b1..4b4aa7b8d 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -83,7 +83,7 @@ func NewBlockchain(ctx context.Context, s storage.Store, cfg config.ProtocolConf 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) { store, err := storage.NewLevelDBStore( ctx, @@ -502,6 +502,7 @@ func (bc *Blockchain) GetBlock(hash util.Uint256) (*Block, error) { return block, nil } +// GetHeader returns data block header identified with the given hash value. func (bc *Blockchain) GetHeader(hash util.Uint256) (*Header, error) { b, err := bc.Get(storage.AppendPrefix(storage.DataBlock, hash.BytesReverse())) if err != nil { diff --git a/pkg/core/transaction/claim.go b/pkg/core/transaction/claim.go index 0b5418506..468ce0f19 100644 --- a/pkg/core/transaction/claim.go +++ b/pkg/core/transaction/claim.go @@ -43,6 +43,7 @@ func (tx *ClaimTX) EncodeBinary(w io.Writer) error { return nil } +// Size returns serialized binary size for this transaction. func (tx *ClaimTX) Size() int { sz := util.GetVarSize(uint64(len(tx.Claims))) for _, claim := range tx.Claims { diff --git a/pkg/core/transaction/contract.go b/pkg/core/transaction/contract.go index 3bcde6d37..e36a1ded4 100644 --- a/pkg/core/transaction/contract.go +++ b/pkg/core/transaction/contract.go @@ -8,6 +8,7 @@ import ( // This TX has not special attributes. type ContractTX struct{} +// NewContractTX creates Transaction of ContractType type. func NewContractTX() *Transaction { return &Transaction{ Type: ContractType, @@ -24,6 +25,7 @@ func (tx *ContractTX) EncodeBinary(w io.Writer) error { return nil } +// Size returns serialized binary size for this transaction. func (tx *ContractTX) Size() int { return 0 } diff --git a/pkg/core/transaction/enrollment.go b/pkg/core/transaction/enrollment.go index 884525afe..752f6b9ee 100644 --- a/pkg/core/transaction/enrollment.go +++ b/pkg/core/transaction/enrollment.go @@ -6,7 +6,7 @@ import ( "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. // The way to sign up is: To construct an EnrollmentTransaction type of transaction, // 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) } +// Size returns serialized binary size for this transaction. func (tx *EnrollmentTX) Size() int { return len(tx.PublicKey.Bytes()) } diff --git a/pkg/core/transaction/invocation.go b/pkg/core/transaction/invocation.go index 54de3fb00..d23a8f59d 100644 --- a/pkg/core/transaction/invocation.go +++ b/pkg/core/transaction/invocation.go @@ -54,6 +54,7 @@ func (tx *InvocationTX) EncodeBinary(w io.Writer) error { return bw.Err } +// Size returns serialized binary size for this transaction. func (tx *InvocationTX) Size() int { sz := util.GetVarSize(tx.Script) if (tx.Version >= 1) { diff --git a/pkg/core/transaction/issue.go b/pkg/core/transaction/issue.go index 3a2af4e9d..1a82d2df6 100644 --- a/pkg/core/transaction/issue.go +++ b/pkg/core/transaction/issue.go @@ -18,6 +18,7 @@ func (tx *IssueTX) EncodeBinary(w io.Writer) error { return nil } +// Size returns serialized binary size for this transaction. func (tx *IssueTX) Size() int { return 0 } diff --git a/pkg/core/transaction/miner.go b/pkg/core/transaction/miner.go index 32c41fa48..3f99ad125 100644 --- a/pkg/core/transaction/miner.go +++ b/pkg/core/transaction/miner.go @@ -21,6 +21,7 @@ func (tx *MinerTX) EncodeBinary(w io.Writer) error { return binary.Write(w, binary.LittleEndian, tx.Nonce) } +// Size returns serialized binary size for this transaction. func (tx *MinerTX) Size() int { return 4 // Nonce } diff --git a/pkg/core/transaction/publish.go b/pkg/core/transaction/publish.go index 9dd896e89..526dc8e73 100644 --- a/pkg/core/transaction/publish.go +++ b/pkg/core/transaction/publish.go @@ -74,6 +74,7 @@ func (tx *PublishTX) EncodeBinary(w io.Writer) error { return bw.Err } +// Size returns serialized binary size for this transaction. func (tx *PublishTX) Size() int { sz := util.GetVarSize(tx.Script) + util.GetVarSize(uint64(len(tx.ParamList))) sz += 1 * len(tx.ParamList) diff --git a/pkg/core/transaction/register.go b/pkg/core/transaction/register.go index 1403e7433..96e5e1c6c 100644 --- a/pkg/core/transaction/register.go +++ b/pkg/core/transaction/register.go @@ -63,6 +63,7 @@ func (tx *RegisterTX) EncodeBinary(w io.Writer) error { return bw.Err } +// Size returns serialized binary size for this transaction. func (tx *RegisterTX) Size() int { return 1 + util.GetVarSize(tx.Name) + tx.Amount.Size() + 1 + len(tx.Owner.Bytes()) + tx.Admin.Size() } diff --git a/pkg/core/transaction/state.go b/pkg/core/transaction/state.go index 66636aebb..5ee0c4a0d 100644 --- a/pkg/core/transaction/state.go +++ b/pkg/core/transaction/state.go @@ -44,6 +44,7 @@ func (tx *StateTX) EncodeBinary(w io.Writer) error { return nil } +// Size returns serialized binary size for this transaction. func (tx *StateTX) Size() int { sz := util.GetVarSize(uint64(len(tx.Descriptors))) for _, desc := range tx.Descriptors { diff --git a/pkg/core/transaction/state_descriptor.go b/pkg/core/transaction/state_descriptor.go index a9447c9db..80a30ab04 100644 --- a/pkg/core/transaction/state_descriptor.go +++ b/pkg/core/transaction/state_descriptor.go @@ -45,6 +45,7 @@ func (s *StateDescriptor) EncodeBinary(w io.Writer) error { return bw.Err } +// Size returns serialized binary size for state descriptor. func (s *StateDescriptor) Size() int { return 1 + util.GetVarSize(s.Key) + util.GetVarSize(s.Value) + util.GetVarSize(s.Field) } diff --git a/pkg/core/transaction/transaction.go b/pkg/core/transaction/transaction.go index 32583196f..90efcc777 100644 --- a/pkg/core/transaction/transaction.go +++ b/pkg/core/transaction/transaction.go @@ -251,7 +251,7 @@ func (t *Transaction) createHash() error { 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 { m := make(map[util.Uint256][]*Input) for _, in := range t.Inputs { diff --git a/pkg/core/transaction/type.go b/pkg/core/transaction/type.go index ae0d8982c..e7cc222f8 100644 --- a/pkg/core/transaction/type.go +++ b/pkg/core/transaction/type.go @@ -3,6 +3,7 @@ package transaction // TXType is the type of a transaction. type TXType uint8 +// Constants for all valid transaction types. const ( MinerType TXType = 0x00 IssueType TXType = 0x01 diff --git a/pkg/crypto/base58.go b/pkg/crypto/base58.go index 43fc91884..c3d168766 100644 --- a/pkg/crypto/base58.go +++ b/pkg/crypto/base58.go @@ -109,7 +109,7 @@ func Base58CheckDecode(s string) (b []byte, err error) { 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 { b = append(b, hash.Checksum(b)...) diff --git a/pkg/crypto/keys/nep2.go b/pkg/crypto/keys/nep2.go index 1dcde69ef..fc40fb899 100644 --- a/pkg/crypto/keys/nep2.go +++ b/pkg/crypto/keys/nep2.go @@ -24,12 +24,14 @@ const ( var nepHeader = []byte{0x01, 0x42} +// ScryptParams is a json-serializable container for scrypt KDF parameters. type ScryptParams struct { N int `json:"n"` R int `json:"r"` P int `json:"p"` } +// NEP2ScryptParams returns scrypt parameters specified in the NEP-2. func NEP2ScryptParams() ScryptParams { return ScryptParams{ N: n, diff --git a/pkg/crypto/keys/private_key.go b/pkg/crypto/keys/private_key.go index 4f975d2b0..9e35590ed 100644 --- a/pkg/crypto/keys/private_key.go +++ b/pkg/crypto/keys/private_key.go @@ -22,6 +22,7 @@ type PrivateKey struct { b []byte } +// NewPrivateKey creates a new random private key. func NewPrivateKey() (*PrivateKey, error) { c := crypto.NewEllipticCurve() b := make([]byte, c.N.BitLen()/8+8) diff --git a/pkg/crypto/keys/publickey.go b/pkg/crypto/keys/publickey.go index ae2b14adf..6bf51657e 100644 --- a/pkg/crypto/keys/publickey.go +++ b/pkg/crypto/keys/publickey.go @@ -168,6 +168,7 @@ func (p *PublicKey) EncodeBinary(w io.Writer) error { return binary.Write(w, binary.LittleEndian, p.Bytes()) } +// Signature returns a NEO-specific hash of the key. func (p *PublicKey) Signature() []byte { b := p.Bytes() b = append([]byte{0x21}, b...) @@ -178,6 +179,7 @@ func (p *PublicKey) Signature() []byte { return sig.Bytes() } +// Address returns a base58-encoded NEO-specific address based on the key hash. func (p *PublicKey) Address() string { var b []byte = p.Signature() diff --git a/pkg/crypto/keys/wif.go b/pkg/crypto/keys/wif.go index 874774a91..4fcd71860 100644 --- a/pkg/crypto/keys/wif.go +++ b/pkg/crypto/keys/wif.go @@ -91,6 +91,7 @@ func WIFDecode(wif string, version byte) (*WIF, error) { return w, nil } +// GetVerificationScript returns NEO VM bytecode with checksig command for the public key. func (wif WIF) GetVerificationScript() ([]byte, error) { const ( pushbytes33 = 0x21 diff --git a/pkg/crypto/merkle_tree.go b/pkg/crypto/merkle_tree.go index a1cf339e8..e47fe4ae0 100644 --- a/pkg/crypto/merkle_tree.go +++ b/pkg/crypto/merkle_tree.go @@ -8,7 +8,6 @@ import ( ) // MerkleTree implementation. - type MerkleTree struct { root *MerkleTreeNode depth int diff --git a/pkg/internal/keytestcases/testcases.go b/pkg/internal/keytestcases/testcases.go index b2fd83366..5213b26d2 100644 --- a/pkg/internal/keytestcases/testcases.go +++ b/pkg/internal/keytestcases/testcases.go @@ -1,5 +1,6 @@ package keytestcases +// Ktype represents key testcase values (different encodings of the key). type Ktype struct { Address, PrivateKey, @@ -9,6 +10,7 @@ type Ktype struct { EncryptedWif string } +// Arr contains a set of known keys in Ktype format. var Arr = []Ktype{ { Address: "ALq7AWrhAueN6mJNqk6FHJjnsEoPRytLdW", diff --git a/pkg/interop/account/account.go b/pkg/interop/account/account.go index c25903c1b..c2e4cb19c 100644 --- a/pkg/interop/account/account.go +++ b/pkg/interop/account/account.go @@ -6,7 +6,7 @@ package account // Account stubs a NEO account type. 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 { return nil } diff --git a/pkg/interop/iterator/iterator.go b/pkg/interop/iterator/iterator.go index c63d3b93d..2dd17d2eb 100644 --- a/pkg/interop/iterator/iterator.go +++ b/pkg/interop/iterator/iterator.go @@ -11,8 +11,8 @@ func Create(items []interface{}) Iterator { return Iterator{} } -// TODO: Better description for this. // Key returns the iterator key. +// TODO: Better description for this. func Key(it Iterator) interface{} { return nil } diff --git a/pkg/interop/transaction/transaction.go b/pkg/interop/transaction/transaction.go index 550c796d4..1acd54814 100644 --- a/pkg/interop/transaction/transaction.go +++ b/pkg/interop/transaction/transaction.go @@ -27,14 +27,14 @@ func GetAttributes(t Transaction) []attribute.Attribute { return []attribute.Attribute{} } -// FIXME: What is the correct return type for this? // GetReferences returns a slice of references for the given transaction. +// FIXME: What is the correct return type for this? func GetReferences(t Transaction) []interface{} { return []interface{}{} } -// FIXME: What is the correct return type for this? // GetUnspentCoins returns the unspent coins for the given transaction. +// FIXME: What is the correct return type for this? func GetUnspentCoins(t Transaction) interface{} { return 0 } diff --git a/pkg/network/payload/merkleblock.go b/pkg/network/payload/merkleblock.go index f39b9789a..3b1e90eae 100644 --- a/pkg/network/payload/merkleblock.go +++ b/pkg/network/payload/merkleblock.go @@ -7,6 +7,7 @@ import ( "github.com/CityOfZion/neo-go/pkg/util" ) +// MerkleBlock represents a merkle block packet payload. type MerkleBlock struct { *core.BlockBase TxCount int @@ -14,6 +15,7 @@ type MerkleBlock struct { Flags []byte } +// DecodeBinary implements the Payload interface. func (m *MerkleBlock) DecodeBinary(r io.Reader) error { m.BlockBase = &core.BlockBase{} if err := m.BlockBase.DecodeBinary(r); err != nil { @@ -31,6 +33,7 @@ func (m *MerkleBlock) DecodeBinary(r io.Reader) error { return br.Err } +// EncodeBinary implements the Payload interface. func (m *MerkleBlock) EncodeBinary(w io.Writer) error { return nil } diff --git a/pkg/network/peer.go b/pkg/network/peer.go index e3b6f3854..6d698a11e 100644 --- a/pkg/network/peer.go +++ b/pkg/network/peer.go @@ -5,6 +5,7 @@ import ( "github.com/CityOfZion/neo-go/pkg/util" ) +// Peer represents a network node neo-go is connected to. type Peer interface { Endpoint() util.Endpoint Disconnect(error) diff --git a/pkg/network/tcp_peer.go b/pkg/network/tcp_peer.go index 6d3cca187..1a63fea7e 100644 --- a/pkg/network/tcp_peer.go +++ b/pkg/network/tcp_peer.go @@ -23,6 +23,7 @@ type TCPPeer struct { wg sync.WaitGroup } +// NewTCPPeer returns a TCPPeer structure based on the given connection. func NewTCPPeer(conn net.Conn) *TCPPeer { return &TCPPeer{ conn: conn, diff --git a/pkg/rpc/client.go b/pkg/rpc/client.go index e21b4ef6a..ef76da4db 100644 --- a/pkg/rpc/client.go +++ b/pkg/rpc/client.go @@ -93,6 +93,7 @@ func NewClient(ctx context.Context, endpoint string, opts ClientOptions) (*Clien }, nil } +// WIF returns WIF structure associated with the client. func (c *Client) WIF() keys.WIF { c.wifMu.Lock() defer c.wifMu.Unlock() @@ -117,12 +118,14 @@ func (c *Client) SetWIF(wif string) error { return nil } +// Balancer is a getter for balance field. func (c *Client) Balancer() BalanceGetter { c.balancerMu.Lock() defer c.balancerMu.Unlock() return c.balancer } +// SetBalancer is a setter for balance field. func (c *Client) SetBalancer(b BalanceGetter) { c.balancerMu.Lock() 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 { c.cliMu.Lock() defer c.cliMu.Unlock() return c.cli } +// SetClient is a setter for client field. func (c *Client) SetClient(cli *http.Client) { c.cliMu.Lock() defer c.cliMu.Unlock() diff --git a/pkg/rpc/neoScanBalanceGetter.go b/pkg/rpc/neoScanBalanceGetter.go index d763d5f24..26f61415c 100644 --- a/pkg/rpc/neoScanBalanceGetter.go +++ b/pkg/rpc/neoScanBalanceGetter.go @@ -11,6 +11,7 @@ import ( errs "github.com/pkg/errors" ) +// GetBalance performs a request to get balance for the address specified. func (s NeoScanServer) GetBalance(address string) ([]*Unspent, error) { var ( err error @@ -49,6 +50,7 @@ func filterSpecificAsset(asset string, balance []*Unspent, assetBalance *Unspent } } +// 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 ( err error diff --git a/pkg/rpc/neoScanTypes.go b/pkg/rpc/neoScanTypes.go index b0134277a..0ac7f2441 100644 --- a/pkg/rpc/neoScanTypes.go +++ b/pkg/rpc/neoScanTypes.go @@ -9,35 +9,37 @@ import "github.com/CityOfZion/neo-go/pkg/util" */ type ( + // NeoScanServer stores NEOSCAN URL and API path NeoScanServer struct { URL string // "protocol://host:port/" 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 per asset + // Unspent stores Unspents per asset Unspent struct { Unspent Unspents Asset string // "NEO" / "GAS" 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 { Balance []*Unspent Address string } ) -// NeoScan returns asset IDs as strings ("NEO"/"GAS"); -// strings might be converted to uint256 assets IDs using this map +// GlobalAssets stores a map of asset IDs to user-friendly strings ("NEO"/"GAS"); var GlobalAssets = map[string]string{ "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b": "NEO", "602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7": "GAS", diff --git a/pkg/rpc/rpc.go b/pkg/rpc/rpc.go index cdf60be7e..81ab1f186 100644 --- a/pkg/rpc/rpc.go +++ b/pkg/rpc/rpc.go @@ -65,7 +65,7 @@ func (c *Client) InvokeFunction(script, operation string, params []smartcontract 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. func (c *Client) Invoke(script string, params []smartcontract.Parameter) (*InvokeScriptResponse, error) { var ( diff --git a/pkg/rpc/stack_param.go b/pkg/rpc/stack_param.go index ff62b5424..00072f2ce 100644 --- a/pkg/rpc/stack_param.go +++ b/pkg/rpc/stack_param.go @@ -10,8 +10,10 @@ import ( "github.com/pkg/errors" ) +// StackParamType represents different types of stack values. type StackParamType int +// All possible StackParamType values are listed here const ( Unknown StackParamType = -1 Signature StackParamType = 0x00 @@ -27,6 +29,7 @@ const ( Void StackParamType = 0xff ) +// String implements the stringer interface. func (t StackParamType) String() string { switch t { case Signature: @@ -56,6 +59,7 @@ func (t StackParamType) String() string { } } +// StackParamTypeFromString converts string into the StackParamType. func StackParamTypeFromString(s string) (StackParamType, error) { switch s { 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) { var ( s = string(data) @@ -174,8 +179,10 @@ func (p *StackParam) UnmarshalJSON(data []byte) (err error) { return } +// StackParams in an array of StackParam (TODO: drop it?). type StackParams []StackParam +// TryParseArray converts an array of StackParam into an array of more appropriate things. func (p StackParams) TryParseArray(vals ...interface{}) error { var ( err error @@ -193,6 +200,7 @@ func (p StackParams) TryParseArray(vals ...interface{}) error { return nil } +// TryParse converts one StackParam into something more appropriate. func (p StackParam) TryParse(dest interface{}) error { var ( err error diff --git a/pkg/rpc/txBuilder.go b/pkg/rpc/txBuilder.go index eaf55f294..df2e85689 100644 --- a/pkg/rpc/txBuilder.go +++ b/pkg/rpc/txBuilder.go @@ -10,6 +10,7 @@ import ( errs "github.com/pkg/errors" ) +// CreateRawContractTransaction returns contract-type Transaction built from specified parameters. func CreateRawContractTransaction(params ContractTxParams) (*transaction.Transaction, error) { var ( err error @@ -67,6 +68,7 @@ func CreateRawContractTransaction(params ContractTxParams) (*transaction.Transac return tx, nil } +// GetInvocationScript returns NEO VM script containing transaction signature. func GetInvocationScript(tx *transaction.Transaction, wif keys.WIF) ([]byte, error) { const ( pushbytes64 = 0x40 diff --git a/pkg/rpc/txTypes.go b/pkg/rpc/txTypes.go index 584d968cf..d15f96ae3 100644 --- a/pkg/rpc/txTypes.go +++ b/pkg/rpc/txTypes.go @@ -12,7 +12,7 @@ import ( ) type ( - // parameters for tx to transfer assets; + // ContractTxParams contains parameters for tx to transfer assets; // includes parameters duplication `sendtoaddress` RPC call params // and also some utility data; ContractTxParams struct { @@ -26,6 +26,7 @@ type ( balancer BalanceGetter } + // BalanceGetter is an interface supporting CalculateInputs() method. BalanceGetter interface { // parameters // address: base58-encoded address assets would be transferred from diff --git a/pkg/rpc/types.go b/pkg/rpc/types.go index 3a51fd9ed..d56fa662b 100644 --- a/pkg/rpc/types.go +++ b/pkg/rpc/types.go @@ -5,6 +5,7 @@ import ( "github.com/CityOfZion/neo-go/pkg/vm" ) +// InvokeScriptResponse stores response for the invoke script call. type InvokeScriptResponse struct { responseHeader Error *Error `json:"error,omitempty"` @@ -73,19 +74,21 @@ type response struct { Result interface{} `json:"result"` } +// SendToAddressResponse stores response for the sendtoaddress call. type SendToAddressResponse struct { responseHeader Error *Error `json:"error"` Result *TxResponse } -// struct represents verbose output of `getrawtransaction` RPC call +// GetRawTxResponse struct represents verbose output of `getrawtransaction` RPC call. type GetRawTxResponse struct { responseHeader Error *Error `json:"error"` Result *RawTxResponse `json:"result"` } +// RawTxResponse stores transaction with blockchain metadata to be sent as a response. type RawTxResponse struct { TxResponse BlockHash string `json:"blockhash"` @@ -93,6 +96,7 @@ type RawTxResponse struct { BlockTime uint `json:"blocktime"` } +// TxResponse stores transaction to be sent as a response. type TxResponse struct { TxID string `json:"txid"` Size int `json:"size"` @@ -106,11 +110,13 @@ type TxResponse struct { Scripts []transaction.Witness `json:"scripts"` } +// Vin represents JSON-serializable tx input. type Vin struct { TxId string `json:"txid"` Vout int `json:"vout"` } +// Vout represents JSON-serializable tx output. type Vout struct { N int `json:"n"` Asset string `json:"asset"` diff --git a/pkg/rpc/wrappers/validate_address.go b/pkg/rpc/wrappers/validate_address.go index 83390976d..cea0ab64a 100644 --- a/pkg/rpc/wrappers/validate_address.go +++ b/pkg/rpc/wrappers/validate_address.go @@ -4,6 +4,7 @@ import ( "github.com/CityOfZion/neo-go/pkg/crypto" ) +// ValidateAddressResponse represents response to validate address call. type ValidateAddressResponse struct { Address interface{} `json:"address"` IsValid bool `json:"isvalid"` diff --git a/pkg/smartcontract/param_context.go b/pkg/smartcontract/param_context.go index 166012bfa..b23d95b2d 100644 --- a/pkg/smartcontract/param_context.go +++ b/pkg/smartcontract/param_context.go @@ -51,6 +51,7 @@ func (pt ParamType) String() string { } } +// MarshalJSON implements the json.Marshaler interface. func (pt ParamType) MarshalJSON() ([]byte, error) { return []byte(`"` + pt.String() + `"`), nil } diff --git a/pkg/vm/stack_item.go b/pkg/vm/stack_item.go index a0d59b3ae..cec438d6b 100644 --- a/pkg/vm/stack_item.go +++ b/pkg/vm/stack_item.go @@ -95,6 +95,7 @@ func (i *BigIntegerItem) MarshalJSON() ([]byte, error) { return json.Marshal(i.value) } +// BoolItem represents a boolean StackItem. type BoolItem struct { value bool } diff --git a/pkg/vm/state.go b/pkg/vm/state.go index 62d4367b2..5f2a549d2 100644 --- a/pkg/vm/state.go +++ b/pkg/vm/state.go @@ -17,10 +17,12 @@ const ( breakState ) +// HasFlag check for State flag presence. func (s State) HasFlag(f State) bool { return s&f != 0 } +// String implements the stringer interface. func (s State) String() string { if s == noneState { return "NONE" @@ -39,6 +41,7 @@ func (s State) String() string { return strings.Join(ss, ", ") } +// StateFromString converts string into the VM State. func StateFromString(s string) (st State, err error) { if s = strings.TrimSpace(s); s == "NONE" { return noneState, nil @@ -60,10 +63,12 @@ func StateFromString(s string) (st State, err error) { return } +// MarshalJSON implements the json.Marshaler interface func (s State) MarshalJSON() (data []byte, err error) { return []byte(`"` + s.String() + `"`), nil } +// UnmarshalJSON implements the json.Marshaler interface func (s *State) UnmarshalJSON(data []byte) (err error) { l := len(data) if l < 2 || data[0] != '"' || data[l-1] != '"' { diff --git a/pkg/vm/tests/bar/bar.go b/pkg/vm/tests/bar/bar.go index c75928251..6f086a556 100644 --- a/pkg/vm/tests/bar/bar.go +++ b/pkg/vm/tests/bar/bar.go @@ -1,5 +1,6 @@ package bar +// Bar is something used for testing purposes (TODO: move somewhere?) type Bar struct { X int Y int diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index eff7dac51..a7d9e4c3b 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -133,6 +133,7 @@ func (v *VM) LoadFile(path string) error { return nil } +// Load initializes the VM with the program given. func (v *VM) Load(prog []byte) { // clear all stacks, it could be a reload. v.istack.Clear() diff --git a/pkg/wallet/wallet.go b/pkg/wallet/wallet.go index 691eca18c..413a318fb 100644 --- a/pkg/wallet/wallet.go +++ b/pkg/wallet/wallet.go @@ -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. func (w *Wallet) CreateAccount(name, passphrase string) error { acc, err := NewAccount()