Skip to content

Commit

Permalink
sidechain/deploy: Drop unused utilities working with contract versions
Browse files Browse the repository at this point in the history
Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
cthulhu-rider committed Oct 23, 2023
1 parent d2402f7 commit 83a5d1e
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 299 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,9 @@ require (
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.11.1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230803162519-f966b187b2e5 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
Expand Down Expand Up @@ -473,7 +472,6 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -665,7 +663,6 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.11.1 h1:ojD5zOW8+7dOGzdnNgersm8aPfcDjhMp12UfG93NIMc=
golang.org/x/tools v0.11.1/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
131 changes: 0 additions & 131 deletions pkg/morph/deploy/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,21 @@ package deploy

import (
"context"
"encoding/json"
"errors"
"fmt"
"strings"
"sync/atomic"
"time"

"github.com/nspcc-dev/neo-go/pkg/core/block"
"github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames"
"github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/neorpc"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
"github.com/nspcc-dev/neofs-contract/common"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -181,125 +169,6 @@ func readNNSOnChainState(b Blockchain) (*state.Contract, error) {
return res, nil
}

// contractVersion describes versioning of NeoFS smart contracts.
type contractVersion struct{ major, minor, patch uint64 }

// space sizes for major and minor versions of the NeoFS contracts.
const majorSpace, minorSpace = 1e6, 1e3

// equals checks if contractVersion equals to the specified SemVer version.
//
//nolint:unused
func (x contractVersion) equals(major, minor, patch uint64) bool {
return x.major == major && x.minor == minor && x.patch == patch
}

// returns contractVersion as single integer.
func (x contractVersion) toUint64() uint64 {
return x.major*majorSpace + x.minor*minorSpace + x.patch
}

// cmp compares x and y and returns:
//
// -1 if x < y
// 0 if x == y
// +1 if x > y
func (x contractVersion) cmp(y contractVersion) int {
xN := x.toUint64()
yN := y.toUint64()
if xN < yN {
return -1
} else if xN == yN {
return 0
}
return 1
}

func (x contractVersion) String() string {
const sep = "."
return fmt.Sprintf("%d%s%d%s%d", x.major, sep, x.minor, sep, x.patch)
}

// parses contractVersion from the invocation result of methodVersion method.
func parseContractVersionFromInvocationResult(res *result.Invoke) (contractVersion, error) {
bigVersionOnChain, err := unwrap.BigInt(res, nil)
if err != nil {
return contractVersion{}, fmt.Errorf("unwrap big integer from '%s' method return: %w", methodVersion, err)
} else if !bigVersionOnChain.IsUint64() {
return contractVersion{}, fmt.Errorf("invalid/unsupported format of the '%s' method return: expected uint64, got %v", methodVersion, bigVersionOnChain)
}

n := bigVersionOnChain.Uint64()

mjr := n / majorSpace

return contractVersion{
major: mjr,
minor: (n - mjr*majorSpace) / minorSpace,
patch: n % minorSpace,
}, nil
}

// readContractOnChainVersion returns current version of the smart contract
// presented in given Blockchain with specified address.
func readContractOnChainVersion(b Blockchain, onChainAddress util.Uint160) (contractVersion, error) {
res, err := invoker.New(b, nil).Call(onChainAddress, methodVersion)
if err != nil {
return contractVersion{}, fmt.Errorf("call '%s' contract method: %w", methodVersion, err)
}

return parseContractVersionFromInvocationResult(res)
}

// readContractLocalVersion returns version of the local smart contract
// represented by its compiled artifacts. Deployment is tested using provided
// invoker on behalf of the committee.
func readContractLocalVersion(rpc invoker.RPCInvoke, committee keys.PublicKeys, localNEF nef.File, localManifest manifest.Manifest, deployArgs ...interface{}) (contractVersion, error) {
multiSigScript, err := smartcontract.CreateMultiSigRedeemScript(smartcontract.GetMajorityHonestNodeCount(len(committee)), committee)
if err != nil {
return contractVersion{}, fmt.Errorf("create committee multi-signature verification script: %w", err)
}

jManifest, err := json.Marshal(localManifest)
if err != nil {
return contractVersion{}, fmt.Errorf("encode manifest into JSON: %w", err)
}

bNEF, err := localNEF.Bytes()
if err != nil {
return contractVersion{}, fmt.Errorf("encode NEF into binary: %w", err)
}

var deployData interface{}
if len(deployArgs) > 0 {
deployData = deployArgs
}

script := io.NewBufBinWriter()
emit.Opcodes(script.BinWriter, opcode.NEWARRAY0)
emit.Int(script.BinWriter, int64(callflag.All))
emit.String(script.BinWriter, methodVersion)
emit.AppCall(script.BinWriter, management.Hash, "deploy", callflag.All, bNEF, jManifest, deployData)
emit.Opcodes(script.BinWriter, opcode.PUSH2, opcode.PICKITEM)
emit.Syscall(script.BinWriter, interopnames.SystemContractCall)

res, err := invoker.New(rpc, []transaction.Signer{
{
Account: util.Uint160{}, // zero hash to avoid 'contract already exists' case
Scopes: transaction.None,
},
{
Account: hash.Hash160(multiSigScript),
Scopes: transaction.Global,
},
}).Run(script.Bytes())
if err != nil {
return contractVersion{}, fmt.Errorf("run test script deploying contract and calling its '%s' method: %w", methodVersion, err)
}

return parseContractVersionFromInvocationResult(res)
}

type transactionGroupWaiter interface {
WaitAny(ctx context.Context, vub uint32, hashes ...util.Uint256) (*state.AppExecResult, error)
}
Expand Down
163 changes: 0 additions & 163 deletions pkg/morph/deploy/util_test.go

This file was deleted.

0 comments on commit 83a5d1e

Please sign in to comment.