forked from TrueCloudLab/neoneo-go
*: apply go 1.19 formatter heuristics
And make manual corrections where needed. See the "Common mistakes and pitfalls" section of https://tip.golang.org/doc/comment.
This commit is contained in:
parent
bb751535d3
commit
916f2293b8
20 changed files with 167 additions and 150 deletions
|
@ -210,6 +210,7 @@ func lastStmtIsReturn(body *ast.BlockStmt) (b bool) {
|
||||||
|
|
||||||
// analyzePkgOrder sets the order in which packages should be processed.
|
// analyzePkgOrder sets the order in which packages should be processed.
|
||||||
// From Go spec:
|
// From Go spec:
|
||||||
|
//
|
||||||
// A package with no imports is initialized by assigning initial values to all its package-level variables
|
// A package with no imports is initialized by assigning initial values to all its package-level variables
|
||||||
// followed by calling all init functions in the order they appear in the source, possibly in multiple files,
|
// followed by calling all init functions in the order they appear in the source, possibly in multiple files,
|
||||||
// as presented to the compiler. If a package has imports, the imported packages are initialized before
|
// as presented to the compiler. If a package has imports, the imported packages are initialized before
|
||||||
|
|
|
@ -1343,9 +1343,11 @@ func (c *codegen) isCallExprSyscall(e ast.Expr) bool {
|
||||||
// TRY-related opcodes handle exception as follows:
|
// TRY-related opcodes handle exception as follows:
|
||||||
// 1. CATCH block is executed only if exception has occurred.
|
// 1. CATCH block is executed only if exception has occurred.
|
||||||
// 2. FINALLY block is always executed, but after catch block.
|
// 2. FINALLY block is always executed, but after catch block.
|
||||||
|
//
|
||||||
// Go `defer` statements are a bit different:
|
// Go `defer` statements are a bit different:
|
||||||
// 1. `defer` is always executed irregardless of whether an exception has occurred.
|
// 1. `defer` is always executed irregardless of whether an exception has occurred.
|
||||||
// 2. `recover` can or can not handle a possible exception.
|
// 2. `recover` can or can not handle a possible exception.
|
||||||
|
//
|
||||||
// Thus, we use the following approach:
|
// Thus, we use the following approach:
|
||||||
// 1. Throwed exception is saved in a static field X, static fields Y and it is set to true.
|
// 1. Throwed exception is saved in a static field X, static fields Y and it is set to true.
|
||||||
// 2. For each defer local there is a dedicated local variable which is set to 1 if `defer` statement
|
// 2. For each defer local there is a dedicated local variable which is set to 1 if `defer` statement
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
|
|
||||||
// inlineCall inlines call of n for function represented by f.
|
// inlineCall inlines call of n for function represented by f.
|
||||||
// Call `f(a,b)` for definition `func f(x,y int)` is translated to block:
|
// Call `f(a,b)` for definition `func f(x,y int)` is translated to block:
|
||||||
|
//
|
||||||
// {
|
// {
|
||||||
// x := a
|
// x := a
|
||||||
// y := b
|
// y := b
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
Package core implements Neo ledger functionality.
|
Package core implements Neo ledger functionality.
|
||||||
It's built around the Blockchain structure that maintains state of the ledger.
|
It's built around the Blockchain structure that maintains state of the ledger.
|
||||||
|
|
||||||
Events
|
# Events
|
||||||
|
|
||||||
You can subscribe to Blockchain events using a set of Subscribe and Unsubscribe
|
You can subscribe to Blockchain events using a set of Subscribe and Unsubscribe
|
||||||
methods. These methods accept channels that will be used to send appropriate
|
methods. These methods accept channels that will be used to send appropriate
|
||||||
|
@ -24,6 +24,5 @@ way they're stored in the block.
|
||||||
Be careful using these subscriptions, this mechanism is not intended to be used
|
Be careful using these subscriptions, this mechanism is not intended to be used
|
||||||
by lots of subscribers and failing to read from event channels can affect
|
by lots of subscribers and failing to read from event channels can affect
|
||||||
other Blockchain operations.
|
other Blockchain operations.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package core
|
package core
|
||||||
|
|
|
@ -4,10 +4,10 @@ Package mpt implements MPT (Merkle-Patricia Trie).
|
||||||
An MPT stores key-value pairs and is a trie over 16-symbol alphabet. https://en.wikipedia.org/wiki/Trie
|
An MPT stores key-value pairs and is a trie over 16-symbol alphabet. https://en.wikipedia.org/wiki/Trie
|
||||||
A trie is a tree where values are stored in leafs and keys are paths from the root to the leaf node.
|
A trie is a tree where values are stored in leafs and keys are paths from the root to the leaf node.
|
||||||
An MPT consists of 4 types of nodes:
|
An MPT consists of 4 types of nodes:
|
||||||
- Leaf node only contains a value.
|
- Leaf node only contains a value.
|
||||||
- Extension node contains both a key and a value.
|
- Extension node contains both a key and a value.
|
||||||
- Branch node contains 2 or more children.
|
- Branch node contains 2 or more children.
|
||||||
- Hash node is a compressed node and only contains the actual node's hash.
|
- Hash node is a compressed node and only contains the actual node's hash.
|
||||||
The actual node must be retrieved from the storage or over the network.
|
The actual node must be retrieved from the storage or over the network.
|
||||||
|
|
||||||
As an example here is a trie containing 3 pairs:
|
As an example here is a trie containing 3 pairs:
|
||||||
|
@ -16,10 +16,10 @@ As an example here is a trie containing 3 pairs:
|
||||||
- 0x1224 -> val3
|
- 0x1224 -> val3
|
||||||
- 0x12 -> val4
|
- 0x12 -> val4
|
||||||
|
|
||||||
ExtensionNode(0x0102), Next
|
ExtensionNode(0x0102), Next
|
||||||
_______________________|
|
_______________________|
|
||||||
|
|
|
|
||||||
BranchNode [0, 1, 2, ...], Last -> Leaf(val4)
|
BranchNode [0, 1, 2, ...], Last -> Leaf(val4)
|
||||||
| |
|
| |
|
||||||
| ExtensionNode [0x04], Next -> Leaf(val3)
|
| ExtensionNode [0x04], Next -> Leaf(val3)
|
||||||
|
|
|
|
||||||
|
|
|
@ -98,6 +98,7 @@ func getEffectiveSize(buf []byte, isNeg bool) int {
|
||||||
// ToBytes converts an integer to a slice in little-endian format.
|
// ToBytes converts an integer to a slice in little-endian format.
|
||||||
// Note: NEO3 serialization differs from default C# BigInteger.ToByteArray()
|
// Note: NEO3 serialization differs from default C# BigInteger.ToByteArray()
|
||||||
// when n == 0. For zero is equal to empty slice in NEO3.
|
// when n == 0. For zero is equal to empty slice in NEO3.
|
||||||
|
//
|
||||||
// https://github.com/neo-project/neo-vm/blob/master/src/neo-vm/Types/Integer.cs#L16
|
// https://github.com/neo-project/neo-vm/blob/master/src/neo-vm/Types/Integer.cs#L16
|
||||||
func ToBytes(n *big.Int) []byte {
|
func ToBytes(n *big.Int) []byte {
|
||||||
return ToPreallocatedBytes(n, []byte{})
|
return ToPreallocatedBytes(n, []byte{})
|
||||||
|
|
|
@ -8,6 +8,7 @@ in the documentation of respective functions.
|
||||||
|
|
||||||
Types defined here are used for proper manifest generation. Here is how Go types
|
Types defined here are used for proper manifest generation. Here is how Go types
|
||||||
correspond to smartcontract and VM types:
|
correspond to smartcontract and VM types:
|
||||||
|
|
||||||
int-like - Integer
|
int-like - Integer
|
||||||
bool - Boolean
|
bool - Boolean
|
||||||
[]byte - ByteArray (Buffer in VM)
|
[]byte - ByteArray (Buffer in VM)
|
||||||
|
@ -15,8 +16,9 @@ correspond to smartcontract and VM types:
|
||||||
(interface{})(nil) - Any
|
(interface{})(nil) - Any
|
||||||
non-byte slice - Array
|
non-byte slice - Array
|
||||||
map[K]V - map
|
map[K]V - map
|
||||||
|
|
||||||
Other types are defined explicitly in this pkg:
|
Other types are defined explicitly in this pkg:
|
||||||
Hash160, Hash256, Interface, PublicKey, Signature
|
[Hash160], [Hash256], [Interface], [PublicKey], [Signature].
|
||||||
|
|
||||||
Note that unless written otherwise structures defined in this packages can't be
|
Note that unless written otherwise structures defined in this packages can't be
|
||||||
correctly created by new() or composite literals, they should be received from
|
correctly created by new() or composite literals, they should be received from
|
||||||
|
|
|
@ -35,31 +35,30 @@ const MinimumResponseGas = 10_000_000
|
||||||
// Request makes an oracle request. It can only be successfully invoked by
|
// Request makes an oracle request. It can only be successfully invoked by
|
||||||
// a deployed contract and it takes the following parameters:
|
// a deployed contract and it takes the following parameters:
|
||||||
//
|
//
|
||||||
// url
|
// - url
|
||||||
// URL to fetch, only https and neofs URLs are supported like
|
// URL to fetch, only https and neofs URLs are supported like
|
||||||
// https://example.com/some.json or
|
// https://example.com/some.json or
|
||||||
// neofs:6pJtLUnGqDxE2EitZYLsDzsfTDVegD6BrRUn8QAFZWyt/5Cyxb3wrHDw5pqY63hb5otCSsJ24ZfYmsA8NAjtho2gr
|
// neofs:6pJtLUnGqDxE2EitZYLsDzsfTDVegD6BrRUn8QAFZWyt/5Cyxb3wrHDw5pqY63hb5otCSsJ24ZfYmsA8NAjtho2gr
|
||||||
//
|
//
|
||||||
// filter
|
// - filter
|
||||||
// JSONPath filter to process the result; if specified, it will be
|
// JSONPath filter to process the result; if specified, it will be
|
||||||
// applied to the data returned from HTTP/NeoFS and you'll only get
|
// applied to the data returned from HTTP/NeoFS and you'll only get
|
||||||
// filtered data in your callback method.
|
// filtered data in your callback method.
|
||||||
//
|
//
|
||||||
// cb
|
// - cb
|
||||||
// name of the method that will process oracle data, it must be a method
|
// name of the method that will process oracle data, it must be a method
|
||||||
// of the same contract that invokes Request and it must have the following
|
// of the same contract that invokes Request and it must have the following
|
||||||
// signature for correct invocation:
|
// signature for correct invocation:
|
||||||
//
|
//
|
||||||
// Method(url string, userData interface{}, code int, result []byte)
|
// - Method(url string, userData interface{}, code int, result []byte)
|
||||||
//
|
|
||||||
// where url is the same url specified for Request, userData is anything
|
// where url is the same url specified for Request, userData is anything
|
||||||
// passed in the next parameter, code is the status of the reply and
|
// passed in the next parameter, code is the status of the reply and
|
||||||
// result is the data returned from the request if any.
|
// result is the data returned from the request if any.
|
||||||
//
|
//
|
||||||
// userData
|
// - userData
|
||||||
// data to pass to the callback function.
|
// data to pass to the callback function.
|
||||||
//
|
//
|
||||||
// gasForResponse
|
// - gasForResponse
|
||||||
// GAS attached to this request for reply callback processing,
|
// GAS attached to this request for reply callback processing,
|
||||||
// note that it's different from the oracle request price, this
|
// note that it's different from the oracle request price, this
|
||||||
// GAS is used for oracle transaction's network and system fees,
|
// GAS is used for oracle transaction's network and system fees,
|
||||||
|
|
|
@ -46,6 +46,7 @@ func JSONSerialize(item interface{}) []byte {
|
||||||
// JSONDeserialize deserializes a value from json. It uses `jsonDeserialize` method of StdLib
|
// JSONDeserialize deserializes a value from json. It uses `jsonDeserialize` method of StdLib
|
||||||
// native contract.
|
// native contract.
|
||||||
// It performs deserialization as follows:
|
// It performs deserialization as follows:
|
||||||
|
//
|
||||||
// strings -> []byte (string) from base64
|
// strings -> []byte (string) from base64
|
||||||
// integers -> (u)int* types
|
// integers -> (u)int* types
|
||||||
// null -> interface{}(nil)
|
// null -> interface{}(nil)
|
||||||
|
|
|
@ -4,12 +4,13 @@ It can be used to implement unit-tests for contracts in Go using regular Go
|
||||||
conventions.
|
conventions.
|
||||||
|
|
||||||
Usually it's used like this:
|
Usually it's used like this:
|
||||||
* an instance of the blockchain is created using chain subpackage
|
|
||||||
* the target contract is compiled using one of Compile* functions
|
- an instance of the blockchain is created using chain subpackage
|
||||||
* and Executor is created for the blockchain
|
- the target contract is compiled using one of Compile* functions
|
||||||
* it's used to deploy a contract with DeployContract
|
- and Executor is created for the blockchain
|
||||||
* CommitteeInvoker and/or ValidatorInvoker are then created to perform test invocations
|
- it's used to deploy a contract with DeployContract
|
||||||
* if needed, NewAccount is used to create an appropriate number of accounts for the test
|
- CommitteeInvoker and/or ValidatorInvoker are then created to perform test invocations
|
||||||
|
- if needed, NewAccount is used to create an appropriate number of accounts for the test
|
||||||
|
|
||||||
Higher-order methods provided in Executor and ContractInvoker hide the details
|
Higher-order methods provided in Executor and ContractInvoker hide the details
|
||||||
of transaction creation for the most part, but there are lower-level methods as
|
of transaction creation for the most part, but there are lower-level methods as
|
||||||
|
|
|
@ -1126,6 +1126,7 @@ func (s *Server) handleGetAddrCmd(p Peer) error {
|
||||||
// 1. If possible, blocks should be fetched in parallel.
|
// 1. If possible, blocks should be fetched in parallel.
|
||||||
// height..+500 to one peer, height+500..+1000 to another etc.
|
// height..+500 to one peer, height+500..+1000 to another etc.
|
||||||
// 2. Every block must eventually be fetched even if the peer sends no answer.
|
// 2. Every block must eventually be fetched even if the peer sends no answer.
|
||||||
|
//
|
||||||
// Thus, the following algorithm is used:
|
// Thus, the following algorithm is used:
|
||||||
// 1. Block range is divided into chunks of payload.MaxHashesCount.
|
// 1. Block range is divided into chunks of payload.MaxHashesCount.
|
||||||
// 2. Send requests for chunk in increasing order.
|
// 2. Send requests for chunk in increasing order.
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
Package rpcclient implements NEO-specific JSON-RPC 2.0 client.
|
Package rpcclient implements NEO-specific JSON-RPC 2.0 client.
|
||||||
This package is currently in beta and is subject to change.
|
This package is currently in beta and is subject to change.
|
||||||
|
|
||||||
Client
|
# Client
|
||||||
|
|
||||||
After creating a client instance with or without a ClientConfig
|
After creating a client instance with or without a ClientConfig
|
||||||
you can interact with the NEO blockchain by its exposed methods.
|
you can interact with the NEO blockchain by its exposed methods.
|
||||||
|
@ -12,6 +12,7 @@ return a more pretty printed response from the server instead of
|
||||||
a raw hex string.
|
a raw hex string.
|
||||||
|
|
||||||
TODO:
|
TODO:
|
||||||
|
|
||||||
Allow client to connect using client cert.
|
Allow client to connect using client cert.
|
||||||
More in-depth examples.
|
More in-depth examples.
|
||||||
|
|
||||||
|
@ -75,6 +76,5 @@ Unsupported methods
|
||||||
sendfrom
|
sendfrom
|
||||||
sendmany
|
sendmany
|
||||||
sendtoaddress
|
sendtoaddress
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package rpcclient
|
package rpcclient
|
||||||
|
|
|
@ -857,6 +857,7 @@ func getSigners(sender *wallet.Account, cosigners []SignerAccount) ([]transactio
|
||||||
// for the attribute and Notary witness.
|
// for the attribute and Notary witness.
|
||||||
// 6. Main transaction either shouldn't have all witnesses attached (in this case none of them
|
// 6. Main transaction either shouldn't have all witnesses attached (in this case none of them
|
||||||
// can be multisignature), or it only should have a partial multisignature.
|
// can be multisignature), or it only should have a partial multisignature.
|
||||||
|
//
|
||||||
// Note: client should be initialized before SignAndPushP2PNotaryRequest call.
|
// Note: client should be initialized before SignAndPushP2PNotaryRequest call.
|
||||||
func (c *Client) SignAndPushP2PNotaryRequest(mainTx *transaction.Transaction, fallbackScript []byte, fallbackSysFee int64, fallbackNetFee int64, fallbackValidFor uint32, acc *wallet.Account) (*payload.P2PNotaryRequest, error) {
|
func (c *Client) SignAndPushP2PNotaryRequest(mainTx *transaction.Transaction, fallbackScript []byte, fallbackSysFee int64, fallbackNetFee int64, fallbackValidFor uint32, acc *wallet.Account) (*payload.P2PNotaryRequest, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
|
@ -141,6 +141,7 @@ func (pt *ParamType) DecodeBinary(r *io.BinReader) {
|
||||||
|
|
||||||
// ParseParamType is a user-friendly string to ParamType converter, it's
|
// ParseParamType is a user-friendly string to ParamType converter, it's
|
||||||
// case-insensitive and makes the following conversions:
|
// case-insensitive and makes the following conversions:
|
||||||
|
//
|
||||||
// signature -> SignatureType
|
// signature -> SignatureType
|
||||||
// bool, boolean -> BoolType
|
// bool, boolean -> BoolType
|
||||||
// int, integer -> IntegerType
|
// int, integer -> IntegerType
|
||||||
|
@ -153,6 +154,7 @@ func (pt *ParamType) DecodeBinary(r *io.BinReader) {
|
||||||
// map -> MapType
|
// map -> MapType
|
||||||
// interopinterface -> InteropInterfaceType
|
// interopinterface -> InteropInterfaceType
|
||||||
// void -> VoidType
|
// void -> VoidType
|
||||||
|
//
|
||||||
// anything else generates an error.
|
// anything else generates an error.
|
||||||
func ParseParamType(typ string) (ParamType, error) {
|
func ParseParamType(typ string) (ParamType, error) {
|
||||||
switch strings.ToLower(typ) {
|
switch strings.ToLower(typ) {
|
||||||
|
|
|
@ -118,6 +118,7 @@ func (u Uint256) MarshalJSON() ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CompareTo compares two Uint256 with each other. Possible output: 1, -1, 0
|
// CompareTo compares two Uint256 with each other. Possible output: 1, -1, 0
|
||||||
|
//
|
||||||
// 1 implies u > other.
|
// 1 implies u > other.
|
||||||
// -1 implies u < other.
|
// -1 implies u < other.
|
||||||
// 0 implies u = other.
|
// 0 implies u = other.
|
||||||
|
|
|
@ -237,6 +237,7 @@ func (s *Stack) RemoveAt(n int) Element {
|
||||||
|
|
||||||
// Dup duplicates and returns the element at position n.
|
// Dup duplicates and returns the element at position n.
|
||||||
// Dup is used for copying elements on the top of its own stack.
|
// Dup is used for copying elements on the top of its own stack.
|
||||||
|
//
|
||||||
// s.Push(s.Peek(0)) // will result in unexpected behavior.
|
// s.Push(s.Peek(0)) // will result in unexpected behavior.
|
||||||
// s.Push(s.Dup(0)) // is the correct approach.
|
// s.Push(s.Dup(0)) // is the correct approach.
|
||||||
func (s *Stack) Dup(n int) Element {
|
func (s *Stack) Dup(n int) Element {
|
||||||
|
@ -246,6 +247,7 @@ func (s *Stack) Dup(n int) Element {
|
||||||
|
|
||||||
// Iter iterates over all elements int the stack, starting from the top
|
// Iter iterates over all elements int the stack, starting from the top
|
||||||
// of the stack.
|
// of the stack.
|
||||||
|
//
|
||||||
// s.Iter(func(elem *Element) {
|
// s.Iter(func(elem *Element) {
|
||||||
// // do something with the element.
|
// // do something with the element.
|
||||||
// })
|
// })
|
||||||
|
@ -257,6 +259,7 @@ func (s *Stack) Iter(f func(Element)) {
|
||||||
|
|
||||||
// IterBack iterates over all elements of the stack, starting from the bottom
|
// IterBack iterates over all elements of the stack, starting from the bottom
|
||||||
// of the stack.
|
// of the stack.
|
||||||
|
//
|
||||||
// s.IterBack(func(elem *Element) {
|
// s.IterBack(func(elem *Element) {
|
||||||
// // do something with the element.
|
// // do something with the element.
|
||||||
// })
|
// })
|
||||||
|
|
|
@ -36,6 +36,7 @@ var ErrTooDeep = errors.New("too deep")
|
||||||
|
|
||||||
// ToJSON encodes Item to JSON.
|
// ToJSON encodes Item to JSON.
|
||||||
// It behaves as following:
|
// It behaves as following:
|
||||||
|
//
|
||||||
// ByteArray -> base64 string
|
// ByteArray -> base64 string
|
||||||
// BigInteger -> number
|
// BigInteger -> number
|
||||||
// Bool -> bool
|
// Bool -> bool
|
||||||
|
@ -153,6 +154,7 @@ func itemToJSONString(it Item) ([]byte, error) {
|
||||||
|
|
||||||
// FromJSON decodes an Item from JSON.
|
// FromJSON decodes an Item from JSON.
|
||||||
// It behaves as following:
|
// It behaves as following:
|
||||||
|
//
|
||||||
// string -> ByteArray from base64
|
// string -> ByteArray from base64
|
||||||
// number -> BigInteger
|
// number -> BigInteger
|
||||||
// bool -> Bool
|
// bool -> Bool
|
||||||
|
|
Loading…
Reference in a new issue