From 524ba5fd1bdf0e2fae54e8a010c5efdc80ae3d3b Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Wed, 9 Oct 2024 18:17:22 +0300 Subject: [PATCH] examples: fix linter issues Signed-off-by: Anna Shaleva --- examples/engine/engine.go | 8 ++++---- examples/iterator/iterator.go | 2 +- examples/nft-nd-nns/nns.go | 8 ++++---- examples/nft-nd-nns/nns_test.go | 2 -- examples/nft-nd/nft.go | 2 +- examples/runtime/runtime.go | 4 ++-- examples/storage/storage.go | 4 ++-- examples/timer/timer.go | 10 +++++----- examples/token/nep17/nep17.go | 17 ++++++++--------- examples/token/token.go | 14 +++++++------- examples/zkp/cubic_circuit/main.go | 2 +- examples/zkp/cubic_circuit/main_test.go | 2 +- examples/zkp/xor_compat/verify.go | 6 +++--- 13 files changed, 39 insertions(+), 42 deletions(-) diff --git a/examples/engine/engine.go b/examples/engine/engine.go index f94e29e03..f7178e908 100644 --- a/examples/engine/engine.go +++ b/examples/engine/engine.go @@ -4,25 +4,25 @@ import ( "github.com/nspcc-dev/neo-go/pkg/interop/runtime" ) -// NotifyScriptContainer sends runtime notification with script container hash +// NotifyScriptContainer sends runtime notification with script container hash. func NotifyScriptContainer() { tx := runtime.GetScriptContainer() runtime.Notify("Tx", tx.Hash) } -// NotifyCallingScriptHash sends runtime notification with calling script hash +// NotifyCallingScriptHash sends runtime notification with calling script hash. func NotifyCallingScriptHash() { callingScriptHash := runtime.GetCallingScriptHash() runtime.Notify("Calling", callingScriptHash) } -// NotifyExecutingScriptHash sends runtime notification about executing script hash +// NotifyExecutingScriptHash sends runtime notification about executing script hash. func NotifyExecutingScriptHash() { execScriptHash := runtime.GetExecutingScriptHash() runtime.Notify("Executing", execScriptHash) } -// NotifyEntryScriptHash sends notification about entry script hash +// NotifyEntryScriptHash sends notification about entry script hash. func NotifyEntryScriptHash() { entryScriptHash := runtime.GetEntryScriptHash() runtime.Notify("Entry", entryScriptHash) diff --git a/examples/iterator/iterator.go b/examples/iterator/iterator.go index f5e91ea37..f18d3ec8f 100644 --- a/examples/iterator/iterator.go +++ b/examples/iterator/iterator.go @@ -7,7 +7,7 @@ import ( ) // _deploy primes contract's storage with some data to be used later. -func _deploy(_ any, _ bool) { +func _deploy(_ any, _ bool) { // nolint: unused ctx := storage.GetContext() // RW context. storage.Put(ctx, "foo1", "1") storage.Put(ctx, "foo2", "2") diff --git a/examples/nft-nd-nns/nns.go b/examples/nft-nd-nns/nns.go index b1dacb7a5..1f02ebfaf 100644 --- a/examples/nft-nd-nns/nns.go +++ b/examples/nft-nd-nns/nns.go @@ -60,7 +60,7 @@ const ( // Other constants. const ( // defaultRegisterPrice is the default price for new domain registration. - defaultRegisterPrice = 10_0000_0000 + defaultRegisterPrice = 10_0000_0000 // nolint: unused // millisecondsInYear is amount of milliseconds per year. millisecondsInYear = 365 * 24 * 3600 * 1000 ) @@ -79,7 +79,7 @@ func Update(nef []byte, manifest string) { } // _deploy initializes defaults (total supply and registration price) on contract deploy. -func _deploy(data any, isUpdate bool) { +func _deploy(data any, isUpdate bool) { // nolint: unused if isUpdate { return } @@ -491,7 +491,7 @@ func getRecordKey(tokenId []byte, name string, typ RecordType) []byte { // isValid returns true if the provided address is a valid Uint160. func isValid(address interop.Hash160) bool { - return address != nil && len(address) == 20 + return address != nil && len(address) == 20 // nolint: gosimple } // checkCommittee panics if the script container is not signed by the committee. @@ -555,7 +555,7 @@ func splitAndCheck(name string, allowMultipleFragments bool) []string { if l > 2 && !allowMultipleFragments { return nil } - for i := 0; i < l; i++ { + for i := range fragments { if !checkFragment(fragments[i], i == l-1) { return nil } diff --git a/examples/nft-nd-nns/nns_test.go b/examples/nft-nd-nns/nns_test.go index 8afc6b9eb..d0d043c7c 100644 --- a/examples/nft-nd-nns/nns_test.go +++ b/examples/nft-nd-nns/nns_test.go @@ -418,11 +418,9 @@ func testTokensOf(t *testing.T, c *neotest.ContractInvoker, result [][]byte, arg } require.NoError(t, err) iter := s.Pop().Interop().Value().(*storage.Iterator) - arr := make([]stackitem.Item, 0, len(result)) for i := range result { require.True(t, iter.Next()) require.Equal(t, result[i], iter.Value().Value()) - arr = append(arr, stackitem.Make(result[i])) } require.False(t, iter.Next()) } diff --git a/examples/nft-nd/nft.go b/examples/nft-nd/nft.go index 96796049d..78a8bc29e 100644 --- a/examples/nft-nd/nft.go +++ b/examples/nft-nd/nft.go @@ -26,7 +26,7 @@ const ( totalSupplyPrefix = "s" // balancePrefix contains map from addresses to balances. balancePrefix = "b" - // accountPrefix contains map from address + token id to tokens + // accountPrefix contains map from address + token id to tokens. accountPrefix = "a" // tokenPrefix contains map from token id to it's owner. tokenPrefix = "t" diff --git a/examples/runtime/runtime.go b/examples/runtime/runtime.go index a98d39d29..2f98e8ecb 100644 --- a/examples/runtime/runtime.go +++ b/examples/runtime/runtime.go @@ -7,7 +7,7 @@ import ( ) var ( - // Check if the invoker of the contract is the specified owner + // Check if the invoker of the contract is the specified owner. owner = address.ToHash160("NbrUYaZgyhSkNoRo9ugRyEMdUZxrhkNaWB") ) @@ -22,7 +22,7 @@ func init() { // _deploy is called after contract deployment or update, it'll be called // in deployment transaction and if call update method of this contract. -func _deploy(_ any, isUpdate bool) { +func _deploy(_ any, isUpdate bool) { // nolint: unused if isUpdate { Log("_deploy method called after contract update") return diff --git a/examples/storage/storage.go b/examples/storage/storage.go index 2fe5f7305..4f6af2a5d 100644 --- a/examples/storage/storage.go +++ b/examples/storage/storage.go @@ -5,13 +5,13 @@ import ( "github.com/nspcc-dev/neo-go/pkg/interop/storage" ) -// ctx holds storage context for contract methods +// ctx holds storage context for contract methods. var ctx storage.Context // defaultKey represents the default key. var defaultKey = []byte("default") -// init inits storage context before any other contract method is called +// init inits storage context before any other contract method is called. func init() { ctx = storage.GetContext() } diff --git a/examples/timer/timer.go b/examples/timer/timer.go index fcc37ef46..d8197a443 100644 --- a/examples/timer/timer.go +++ b/examples/timer/timer.go @@ -9,15 +9,15 @@ import ( "github.com/nspcc-dev/neo-go/pkg/interop/storage" ) -const defaultTicks = 3 +const defaultTicks = 3 // nolint: unused const mgmtKey = "mgmt" var ( - // ctx holds storage context for contract methods + // ctx holds storage context for contract methods. ctx storage.Context - // Check if the invoker of the contract is the specified owner + // Check if the invoker of the contract is the specified owner. owner = address.ToHash160("NbrUYaZgyhSkNoRo9ugRyEMdUZxrhkNaWB") - // ticksKey is a storage key for ticks counter + // ticksKey is a storage key for ticks counter. ticksKey = []byte("ticks") ) @@ -25,7 +25,7 @@ func init() { ctx = storage.GetContext() } -func _deploy(_ any, isUpdate bool) { +func _deploy(_ any, isUpdate bool) { // nolint: unused if isUpdate { ticksLeft := storage.Get(ctx, ticksKey).(int) + 1 storage.Put(ctx, ticksKey, ticksLeft) diff --git a/examples/token/nep17/nep17.go b/examples/token/nep17/nep17.go index dc4702d5a..4d4ff4e73 100644 --- a/examples/token/nep17/nep17.go +++ b/examples/token/nep17/nep17.go @@ -8,7 +8,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/interop/storage" ) -// Token holds all token info +// Token holds all token info. type Token struct { // Token name Name string @@ -35,17 +35,17 @@ func getIntFromDB(ctx storage.Context, key []byte) int { return res } -// GetSupply gets the token totalSupply value from VM storage +// GetSupply gets the token totalSupply value from VM storage. func (t Token) GetSupply(ctx storage.Context) int { return getIntFromDB(ctx, []byte(t.CirculationKey)) } -// BalanceOf gets the token balance of a specific address +// BalanceOf gets the token balance of a specific address. func (t Token) BalanceOf(ctx storage.Context, holder []byte) int { return getIntFromDB(ctx, holder) } -// Transfer token from one user to another +// Transfer token from one user to another. func (t Token) Transfer(ctx storage.Context, from, to interop.Hash160, amount int, data any) bool { amountFrom := t.CanTransfer(ctx, from, to, amount) if amountFrom == -1 { @@ -74,7 +74,7 @@ func (t Token) Transfer(ctx storage.Context, from, to interop.Hash160, amount in return true } -// CanTransfer returns the amount it can transfer +// CanTransfer returns the amount it can transfer. func (t Token) CanTransfer(ctx storage.Context, from []byte, to []byte, amount int) int { if len(to) != 20 || !IsUsableAddress(from) { return -1 @@ -94,10 +94,9 @@ func (t Token) CanTransfer(ctx storage.Context, from []byte, to []byte, amount i return amountFrom } -// IsUsableAddress checks if the sender is either the correct Neo address or SC address +// IsUsableAddress checks if the sender is either the correct Neo address or SC address. func IsUsableAddress(addr []byte) bool { if len(addr) == 20 { - if runtime.CheckWitness(addr) { return true } @@ -112,13 +111,13 @@ func IsUsableAddress(addr []byte) bool { return false } -// Mint initial supply of tokens +// Mint initial supply of tokens. func (t Token) Mint(ctx storage.Context, to interop.Hash160) bool { if !IsUsableAddress(t.Owner) { return false } minted := storage.Get(ctx, []byte("minted")) - if minted != nil && minted.(bool) == true { + if minted != nil && minted.(bool) { return false } diff --git a/examples/token/token.go b/examples/token/token.go index 47f4308bb..4a6d8daa5 100644 --- a/examples/token/token.go +++ b/examples/token/token.go @@ -19,7 +19,7 @@ var ( ) // init initializes Token Interface and storage context for the Smart -// Contract to operate with +// Contract to operate with. func init() { token = nep17.Token{ Name: "Awesome NEO Token", @@ -32,32 +32,32 @@ func init() { ctx = storage.GetContext() } -// Symbol returns the token symbol +// Symbol returns the token symbol. func Symbol() string { return token.Symbol } -// Decimals returns the token decimals +// Decimals returns the token decimals. func Decimals() int { return token.Decimals } -// TotalSupply returns the token total supply value +// TotalSupply returns the token total supply value. func TotalSupply() int { return token.GetSupply(ctx) } -// BalanceOf returns the amount of token on the specified address +// BalanceOf returns the amount of token on the specified address. func BalanceOf(holder interop.Hash160) int { return token.BalanceOf(ctx, holder) } -// Transfer token from one user to another +// Transfer token from one user to another. func Transfer(from interop.Hash160, to interop.Hash160, amount int, data any) bool { return token.Transfer(ctx, from, to, amount, data) } -// Mint initial supply of tokens +// Mint initial supply of tokens. func Mint(to interop.Hash160) bool { return token.Mint(ctx, to) } diff --git a/examples/zkp/cubic_circuit/main.go b/examples/zkp/cubic_circuit/main.go index 4afb66c86..eb916574c 100644 --- a/examples/zkp/cubic_circuit/main.go +++ b/examples/zkp/cubic_circuit/main.go @@ -51,7 +51,7 @@ func (circuit *CubicCircuit) Define(api frontend.API) error { // main demonstrates how to build the proof and verify it with the help of gnark // library. Error handling omitted intentionally to simplify the example. -func main() { +func main() { // nolint: unused var ( circuit CubicCircuit assignment = CubicCircuit{X: 3, Y: 35} diff --git a/examples/zkp/cubic_circuit/main_test.go b/examples/zkp/cubic_circuit/main_test.go index 1c9518657..babced1ff 100644 --- a/examples/zkp/cubic_circuit/main_test.go +++ b/examples/zkp/cubic_circuit/main_test.go @@ -315,7 +315,7 @@ func setup(t *testing.T, ccs constraint.ConstraintSystem, phase1ResponsePath str // receive a []byte, deserialize it, add his contribution and send back to // coordinator, like it is done in https://github.com/bnb-chain/zkbnb-setup // for BN254 elliptic curve. - for i := range nContributionsPhase2 { + for range nContributionsPhase2 { srs2.Contribute() } diff --git a/examples/zkp/xor_compat/verify.go b/examples/zkp/xor_compat/verify.go index 4a9c82d1a..8955cea66 100644 --- a/examples/zkp/xor_compat/verify.go +++ b/examples/zkp/xor_compat/verify.go @@ -43,7 +43,7 @@ var ( // proving system and is taken from the // https://github.com/neo-project/neo/issues/2647#issuecomment-1002893109 without // changes. The verification process checks the following equality: -// A * B = alpha * beta + sum(pub_input[i] * (beta * u_i(x) + alpha * v_i(x) + w_i(x)) / gamma) * gamma + C * delta +// A * B = alpha * beta + sum(pub_input[i] * (beta * u_i(x) + alpha * v_i(x) + w_i(x)) / gamma) * gamma + C * delta. func VerifyProof(a []byte, b []byte, c []byte, publicInput [][]byte) bool { alphaPoint := crypto.Bls12381Deserialize(alpha) betaPoint := crypto.Bls12381Deserialize(beta) @@ -68,11 +68,11 @@ func VerifyProof(a []byte, b []byte, c []byte, publicInput [][]byte) bool { panic("error: inputlen or iclen") } icPoints := make([]crypto.Bls12381Point, iclen) - for i := 0; i < iclen; i++ { + for i := range icPoints { icPoints[i] = crypto.Bls12381Deserialize(ic[i]) } acc := icPoints[0] - for i := 0; i < inputlen; i++ { + for i := range publicInput { scalar := publicInput[i] // 32-bytes LE field element. temp := crypto.Bls12381Mul(icPoints[i+1], scalar, false) acc = crypto.Bls12381Add(acc, temp)