*: 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:
Anna Shaleva 2022-08-08 13:23:21 +03:00
parent bb751535d3
commit 916f2293b8
20 changed files with 167 additions and 150 deletions

View file

@ -210,6 +210,7 @@ func lastStmtIsReturn(body *ast.BlockStmt) (b bool) {
// analyzePkgOrder sets the order in which packages should be processed.
// From Go spec:
//
// 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,
// as presented to the compiler. If a package has imports, the imported packages are initialized before

View file

@ -1343,9 +1343,11 @@ func (c *codegen) isCallExprSyscall(e ast.Expr) bool {
// TRY-related opcodes handle exception as follows:
// 1. CATCH block is executed only if exception has occurred.
// 2. FINALLY block is always executed, but after catch block.
//
// Go `defer` statements are a bit different:
// 1. `defer` is always executed irregardless of whether an exception has occurred.
// 2. `recover` can or can not handle a possible exception.
//
// 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.
// 2. For each defer local there is a dedicated local variable which is set to 1 if `defer` statement

View file

@ -15,6 +15,7 @@ import (
// 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:
//
// {
// x := a
// y := b

View file

@ -2,7 +2,7 @@
Package core implements Neo ledger functionality.
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
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
by lots of subscribers and failing to read from event channels can affect
other Blockchain operations.
*/
package core

View file

@ -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
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:
- Leaf node only contains a value.
- Extension node contains both a key and a value.
- Branch node contains 2 or more children.
- Hash node is a compressed node and only contains the actual node's hash.
- Leaf node only contains a value.
- Extension node contains both a key and a value.
- Branch node contains 2 or more children.
- 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.
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
- 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)
|

View file

@ -98,6 +98,7 @@ func getEffectiveSize(buf []byte, isNeg bool) int {
// ToBytes converts an integer to a slice in little-endian format.
// Note: NEO3 serialization differs from default C# BigInteger.ToByteArray()
// 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
func ToBytes(n *big.Int) []byte {
return ToPreallocatedBytes(n, []byte{})

View file

@ -8,6 +8,7 @@ in the documentation of respective functions.
Types defined here are used for proper manifest generation. Here is how Go types
correspond to smartcontract and VM types:
int-like - Integer
bool - Boolean
[]byte - ByteArray (Buffer in VM)
@ -15,8 +16,9 @@ correspond to smartcontract and VM types:
(interface{})(nil) - Any
non-byte slice - Array
map[K]V - map
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
correctly created by new() or composite literals, they should be received from

View file

@ -35,31 +35,30 @@ const MinimumResponseGas = 10_000_000
// Request makes an oracle request. It can only be successfully invoked by
// a deployed contract and it takes the following parameters:
//
// url
// - url
// URL to fetch, only https and neofs URLs are supported like
// https://example.com/some.json or
// neofs:6pJtLUnGqDxE2EitZYLsDzsfTDVegD6BrRUn8QAFZWyt/5Cyxb3wrHDw5pqY63hb5otCSsJ24ZfYmsA8NAjtho2gr
//
// filter
// - filter
// JSONPath filter to process the result; if specified, it will be
// applied to the data returned from HTTP/NeoFS and you'll only get
// filtered data in your callback method.
//
// cb
// - cb
// 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
// 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
// passed in the next parameter, code is the status of the reply and
// result is the data returned from the request if any.
//
// userData
// - userData
// data to pass to the callback function.
//
// gasForResponse
// - gasForResponse
// GAS attached to this request for reply callback processing,
// note that it's different from the oracle request price, this
// GAS is used for oracle transaction's network and system fees,

View file

@ -46,6 +46,7 @@ func JSONSerialize(item interface{}) []byte {
// JSONDeserialize deserializes a value from json. It uses `jsonDeserialize` method of StdLib
// native contract.
// It performs deserialization as follows:
//
// strings -> []byte (string) from base64
// integers -> (u)int* types
// null -> interface{}(nil)

View file

@ -4,12 +4,13 @@ It can be used to implement unit-tests for contracts in Go using regular Go
conventions.
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
* and Executor is created for the blockchain
* it's used to deploy a contract with DeployContract
* 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
- an instance of the blockchain is created using chain subpackage
- the target contract is compiled using one of Compile* functions
- and Executor is created for the blockchain
- it's used to deploy a contract with DeployContract
- 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
of transaction creation for the most part, but there are lower-level methods as

View file

@ -1126,6 +1126,7 @@ func (s *Server) handleGetAddrCmd(p Peer) error {
// 1. If possible, blocks should be fetched in parallel.
// 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.
//
// Thus, the following algorithm is used:
// 1. Block range is divided into chunks of payload.MaxHashesCount.
// 2. Send requests for chunk in increasing order.

View file

@ -2,7 +2,7 @@
Package rpcclient implements NEO-specific JSON-RPC 2.0 client.
This package is currently in beta and is subject to change.
Client
# Client
After creating a client instance with or without a ClientConfig
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.
TODO:
Allow client to connect using client cert.
More in-depth examples.
@ -75,6 +76,5 @@ Unsupported methods
sendfrom
sendmany
sendtoaddress
*/
package rpcclient

View file

@ -857,6 +857,7 @@ func getSigners(sender *wallet.Account, cosigners []SignerAccount) ([]transactio
// for the attribute and Notary witness.
// 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.
//
// 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) {
var err error

View file

@ -141,6 +141,7 @@ func (pt *ParamType) DecodeBinary(r *io.BinReader) {
// ParseParamType is a user-friendly string to ParamType converter, it's
// case-insensitive and makes the following conversions:
//
// signature -> SignatureType
// bool, boolean -> BoolType
// int, integer -> IntegerType
@ -153,6 +154,7 @@ func (pt *ParamType) DecodeBinary(r *io.BinReader) {
// map -> MapType
// interopinterface -> InteropInterfaceType
// void -> VoidType
//
// anything else generates an error.
func ParseParamType(typ string) (ParamType, error) {
switch strings.ToLower(typ) {

View file

@ -118,6 +118,7 @@ func (u Uint256) MarshalJSON() ([]byte, error) {
}
// CompareTo compares two Uint256 with each other. Possible output: 1, -1, 0
//
// 1 implies u > other.
// -1 implies u < other.
// 0 implies u = other.

View file

@ -237,6 +237,7 @@ func (s *Stack) RemoveAt(n int) Element {
// Dup duplicates and returns the element at position n.
// 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.Dup(0)) // is the correct approach.
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
// of the stack.
//
// s.Iter(func(elem *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
// of the stack.
//
// s.IterBack(func(elem *Element) {
// // do something with the element.
// })

View file

@ -36,6 +36,7 @@ var ErrTooDeep = errors.New("too deep")
// ToJSON encodes Item to JSON.
// It behaves as following:
//
// ByteArray -> base64 string
// BigInteger -> number
// Bool -> bool
@ -153,6 +154,7 @@ func itemToJSONString(it Item) ([]byte, error) {
// FromJSON decodes an Item from JSON.
// It behaves as following:
//
// string -> ByteArray from base64
// number -> BigInteger
// bool -> Bool