examples: fix linter issues

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
Anna Shaleva 2024-10-09 18:17:22 +03:00
parent 949ed4f2ea
commit 524ba5fd1b
13 changed files with 39 additions and 42 deletions

View file

@ -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)

View file

@ -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")

View file

@ -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
}

View file

@ -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())
}

View file

@ -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"

View file

@ -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

View file

@ -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()
}

View file

@ -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)

View file

@ -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
}

View file

@ -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)
}

View file

@ -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}

View file

@ -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()
}

View file

@ -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)