forked from TrueCloudLab/frostfs-contract
Update neo-go to v0.90.0-pre and fix smart-contract
Neo-go v0.90.0-pre implements neo3 features.
This commit is contained in:
parent
94d44953e5
commit
b9ca56d891
4 changed files with 44 additions and 41 deletions
2
go.mod
2
go.mod
|
@ -4,7 +4,7 @@ go 1.12
|
|||
|
||||
require (
|
||||
github.com/mr-tron/base58 v1.1.3 // indirect
|
||||
github.com/nspcc-dev/neo-go v0.75.0
|
||||
github.com/nspcc-dev/neo-go v0.90.0-pre.0.20200709120952-d234db9864e2
|
||||
github.com/nspcc-dev/neofs-crypto v0.3.0
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/stretchr/testify v1.5.1
|
||||
|
|
9
go.sum
9
go.sum
|
@ -2,6 +2,7 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
|
|||
github.com/CityOfZion/neo-go v0.62.1-pre.0.20191114145240-e740fbe708f8/go.mod h1:MJCkWUBhi9pn/CrYO1Q3P687y2KeahrOPS9BD9LDGb0=
|
||||
github.com/CityOfZion/neo-go v0.70.1-pre.0.20191209120015-fccb0085941e/go.mod h1:0enZl0az8xA6PVkwzEOwPWVJGqlt/GO4hA4kmQ5Xzig=
|
||||
github.com/CityOfZion/neo-go v0.70.1-pre.0.20191212173117-32ac01130d4c/go.mod h1:JtlHfeqLywZLswKIKFnAp+yzezY4Dji9qlfQKB2OD/I=
|
||||
github.com/CityOfZion/neo-go v0.71.1-pre.0.20200129171427-f773ec69fb84 h1:gcTXk9aO+PhHudJNPFJ9H4RmKjdzz40Tvv2NE1BwRZ0=
|
||||
github.com/CityOfZion/neo-go v0.71.1-pre.0.20200129171427-f773ec69fb84/go.mod h1:FLI526IrRWHmcsO+mHsCbj64pJZhwQFTLJZu+A4PGOA=
|
||||
github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
|
||||
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
|
||||
|
@ -37,6 +38,7 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn
|
|||
github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw=
|
||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:rZfgFAXFS/z/lEd6LJmf9HVZ1LkgYiHx5pHhV5DR16M=
|
||||
github.com/frankban/quicktest v1.10.0/go.mod h1:ui7WezCLWMWxVWr1GETZY3smRy0G4KWq9vcPtJmFl7Y=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||
|
@ -54,6 +56,7 @@ github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8l
|
|||
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
|
@ -66,6 +69,7 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv
|
|||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
|
@ -91,9 +95,12 @@ github.com/nspcc-dev/dbft v0.0.0-20191209120240-0d6b7568d9ae/go.mod h1:3FjXOoHmA
|
|||
github.com/nspcc-dev/dbft v0.0.0-20200117124306-478e5cfbf03a/go.mod h1:/YFK+XOxxg0Bfm6P92lY5eDSLYfp06XOdL8KAVgXjVk=
|
||||
github.com/nspcc-dev/dbft v0.0.0-20200219114139-199d286ed6c1/go.mod h1:O0qtn62prQSqizzoagHmuuKoz8QMkU3SzBoKdEvm3aQ=
|
||||
github.com/nspcc-dev/dbft v0.0.0-20200303183127-36d3da79c682/go.mod h1:1FYQXSbb6/9HQIkoF8XO7W/S8N7AZRkBsgwbcXRvk0E=
|
||||
github.com/nspcc-dev/dbft v0.0.0-20200623100921-5a182c20965e/go.mod h1:1FYQXSbb6/9HQIkoF8XO7W/S8N7AZRkBsgwbcXRvk0E=
|
||||
github.com/nspcc-dev/neo-go v0.73.1-pre.0.20200303142215-f5a1b928ce09/go.mod h1:pPYwPZ2ks+uMnlRLUyXOpLieaDQSEaf4NM3zHVbRjmg=
|
||||
github.com/nspcc-dev/neo-go v0.75.0 h1:JX87gmRa0qJ7bMIDwqroQPEz7Y81feinvXq2pbKfpNE=
|
||||
github.com/nspcc-dev/neo-go v0.75.0/go.mod h1:wtCZzd6wm1z+FKrZZD4q2wyUvWmwRx9y9v2N9i0NVM4=
|
||||
github.com/nspcc-dev/neo-go v0.90.0-pre.0.20200709120952-d234db9864e2 h1:+5yZQtwlTY2klOejyEmPHIkimZBZ3qKaOQ0+CU/2G/I=
|
||||
github.com/nspcc-dev/neo-go v0.90.0-pre.0.20200709120952-d234db9864e2/go.mod h1:Y27fkOIYUVt2yAoYkb833F45/q6pdLRdeAZKawHcpfE=
|
||||
github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA=
|
||||
github.com/nspcc-dev/neofs-crypto v0.2.3/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw=
|
||||
github.com/nspcc-dev/neofs-crypto v0.3.0 h1:zlr3pgoxuzrmGCxc5W8dGVfA9Rro8diFvVnBg0L4ifM=
|
||||
|
@ -106,6 +113,7 @@ github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+
|
|||
github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||
github.com/pierrec/lz4 v2.5.2+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
|
@ -190,6 +198,7 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|||
golang.org/x/tools v0.0.0-20180318012157-96caea41033d/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 h1:5Beo0mZN8dRzgrMMkDp0jc8YXQKx9DiJ2k1dkvGsn5A=
|
||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/abiosoft/ishell.v2 v2.0.0/go.mod h1:sFp+cGtH6o4s1FtpVPTMcHq2yue+c4DGOVohJCPUzwY=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
|
|
@ -1,12 +1,2 @@
|
|||
---
|
||||
|
||||
project:
|
||||
author: Neo SPCC
|
||||
email: ops@nspcc.ru
|
||||
version: 0.99
|
||||
name: Neofs Smart Contract
|
||||
hasstorage: true
|
||||
hasdynamicinvocation: true
|
||||
ispayable: true
|
||||
returntype: ByteArray
|
||||
parameters: ['String', 'Array']
|
||||
ispayable: false
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package smart_contract
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/binary"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/blockchain"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/crypto"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/engine"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/transaction"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/util"
|
||||
)
|
||||
|
||||
|
@ -79,14 +79,14 @@ func Main(op string, args []interface{}) interface{} {
|
|||
irList = append(irList, node{pub: pub})
|
||||
}
|
||||
|
||||
data := runtime.Serialize(irList)
|
||||
data := binary.Serialize(irList)
|
||||
storage.Put(ctx, "InnerRingList", data)
|
||||
|
||||
data = runtime.Serialize([]interface{}{})
|
||||
data = binary.Serialize([]interface{}{})
|
||||
storage.Put(ctx, "UsedVerifCheckList", data)
|
||||
storage.Put(ctx, "InnerRingCandidates", data)
|
||||
|
||||
data = runtime.Serialize([]ballot{})
|
||||
data = binary.Serialize([]ballot{})
|
||||
storage.Put(ctx, voteKey, data)
|
||||
|
||||
return true
|
||||
|
@ -116,7 +116,7 @@ func Main(op string, args []interface{}) interface{} {
|
|||
}
|
||||
|
||||
from := pubToScriptHash(key)
|
||||
to := engine.GetExecutingScriptHash()
|
||||
to := runtime.GetExecutingScriptHash()
|
||||
params := []interface{}{from, to, innerRingCandidateFee}
|
||||
|
||||
transferred := engine.AppCall([]byte(tokenHash), "transfer", params).(bool)
|
||||
|
@ -142,7 +142,7 @@ func Main(op string, args []interface{}) interface{} {
|
|||
}
|
||||
|
||||
from := pubToScriptHash(pk)
|
||||
to := engine.GetExecutingScriptHash()
|
||||
to := runtime.GetExecutingScriptHash()
|
||||
params := []interface{}{from, to, amount}
|
||||
transferred := engine.AppCall([]byte(tokenHash), "transfer", params).(bool)
|
||||
if !transferred {
|
||||
|
@ -156,8 +156,7 @@ func Main(op string, args []interface{}) interface{} {
|
|||
rcv = args[2].([]byte) // todo: check if rcv value is valid
|
||||
}
|
||||
|
||||
tx := engine.GetScriptContainer()
|
||||
txHash := transaction.GetHash(tx)
|
||||
txHash := runtime.GetScriptContainer().Hash
|
||||
|
||||
runtime.Notify("Deposit", pk, amount, rcv, txHash)
|
||||
|
||||
|
@ -178,8 +177,7 @@ func Main(op string, args []interface{}) interface{} {
|
|||
amount = amount * 100000000
|
||||
}
|
||||
|
||||
tx := engine.GetScriptContainer()
|
||||
txHash := transaction.GetHash(tx)
|
||||
txHash := runtime.GetScriptContainer().Hash
|
||||
|
||||
runtime.Notify("Withdraw", user, amount, txHash)
|
||||
|
||||
|
@ -196,7 +194,7 @@ func Main(op string, args []interface{}) interface{} {
|
|||
|
||||
ctx := storage.GetContext()
|
||||
|
||||
hashID := crypto.Hash256(id)
|
||||
hashID := crypto.SHA256(id)
|
||||
irList := getSerialized(ctx, "InnerRingList").([]node)
|
||||
usedList := getSerialized(ctx, "UsedVerifCheckList").([]check)
|
||||
threshold := len(irList)/3*2 + 1
|
||||
|
@ -215,7 +213,7 @@ func Main(op string, args []interface{}) interface{} {
|
|||
if n >= threshold {
|
||||
removeVotes(ctx, hashID)
|
||||
|
||||
from := engine.GetExecutingScriptHash()
|
||||
from := runtime.GetExecutingScriptHash()
|
||||
params := []interface{}{from, user, amount}
|
||||
|
||||
transferred := engine.AppCall([]byte(tokenHash), "transfer", params).(bool)
|
||||
|
@ -252,7 +250,7 @@ func Main(op string, args []interface{}) interface{} {
|
|||
panic("innerRingUpdate: cheque has non unique id")
|
||||
}
|
||||
|
||||
chequeHash := crypto.Hash256(data)
|
||||
chequeHash := crypto.SHA256(data)
|
||||
|
||||
n := vote(ctx, chequeHash, irKey)
|
||||
if n >= threshold {
|
||||
|
@ -292,7 +290,7 @@ func Main(op string, args []interface{}) interface{} {
|
|||
delSerializedIR(ctx, "InnerRingCandidates", n.pub)
|
||||
}
|
||||
|
||||
newIRData := runtime.Serialize(newIR)
|
||||
newIRData := binary.Serialize(newIR)
|
||||
storage.Put(ctx, "InnerRingList", newIRData)
|
||||
putSerialized(ctx, "UsedVerifCheckList", c)
|
||||
|
||||
|
@ -327,10 +325,11 @@ func Main(op string, args []interface{}) interface{} {
|
|||
panic("unknown operation")
|
||||
}
|
||||
|
||||
// fixme: use strict type deserialization wrappers
|
||||
func getSerialized(ctx storage.Context, key string) interface{} {
|
||||
data := storage.Get(ctx, key).([]byte)
|
||||
if len(data) != 0 {
|
||||
return runtime.Deserialize(data)
|
||||
return binary.Deserialize(data)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -341,7 +340,7 @@ func delSerialized(ctx storage.Context, key string, value []byte) bool {
|
|||
|
||||
var newList [][]byte
|
||||
if len(data) != 0 {
|
||||
lst := runtime.Deserialize(data).([][]byte)
|
||||
lst := binary.Deserialize(data).([][]byte)
|
||||
for i := 0; i < len(lst); i++ {
|
||||
if util.Equals(value, lst[i]) {
|
||||
deleted = true
|
||||
|
@ -351,7 +350,7 @@ func delSerialized(ctx storage.Context, key string, value []byte) bool {
|
|||
}
|
||||
if deleted {
|
||||
if len(newList) != 0 {
|
||||
data := runtime.Serialize(newList)
|
||||
data := binary.Serialize(newList)
|
||||
storage.Put(ctx, key, data)
|
||||
} else {
|
||||
storage.Delete(ctx, key)
|
||||
|
@ -371,22 +370,27 @@ func putSerialized(ctx storage.Context, key string, value interface{}) bool {
|
|||
|
||||
var lst []interface{}
|
||||
if len(data) != 0 {
|
||||
lst = runtime.Deserialize(data).([]interface{})
|
||||
lst = binary.Deserialize(data).([]interface{})
|
||||
}
|
||||
|
||||
lst = append(lst, value)
|
||||
data = runtime.Serialize(lst)
|
||||
data = binary.Serialize(lst)
|
||||
storage.Put(ctx, key, data)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func pubToScriptHash(pkey []byte) []byte {
|
||||
pre := []byte{0x21}
|
||||
buf := append(pre, pkey...)
|
||||
buf = append(buf, 0xac)
|
||||
h := crypto.Hash160(buf)
|
||||
return h
|
||||
// pre := []byte{0x21}
|
||||
// buf := append(pre, pkey...)
|
||||
// buf = append(buf, 0xac)
|
||||
// h := crypto.Hash160(buf)
|
||||
//
|
||||
// return h
|
||||
|
||||
// fixme: someday ripemd syscall will appear
|
||||
// or simply store script-hashes along with public key
|
||||
return []byte{0x0F, 0xED}
|
||||
}
|
||||
|
||||
func containsCheck(lst []check, c check) bool {
|
||||
|
@ -413,7 +417,7 @@ func delSerializedIR(ctx storage.Context, key string, value []byte) bool {
|
|||
|
||||
newList := []node{}
|
||||
if len(data) != 0 {
|
||||
lst := runtime.Deserialize(data).([]node)
|
||||
lst := binary.Deserialize(data).([]node)
|
||||
for i := 0; i < len(lst); i++ {
|
||||
n := lst[i]
|
||||
if util.Equals(value, n.pub) {
|
||||
|
@ -423,7 +427,7 @@ func delSerializedIR(ctx storage.Context, key string, value []byte) bool {
|
|||
}
|
||||
}
|
||||
if deleted {
|
||||
data := runtime.Serialize(newList)
|
||||
data := binary.Serialize(newList)
|
||||
storage.Put(ctx, key, data)
|
||||
runtime.Log("target element has been removed")
|
||||
return true
|
||||
|
@ -485,7 +489,7 @@ func vote(ctx storage.Context, id, from []byte) int {
|
|||
found = 1
|
||||
}
|
||||
|
||||
data := runtime.Serialize(newCandidates)
|
||||
data := binary.Serialize(newCandidates)
|
||||
storage.Put(ctx, voteKey, data)
|
||||
|
||||
return found
|
||||
|
@ -504,6 +508,6 @@ func removeVotes(ctx storage.Context, id []byte) {
|
|||
}
|
||||
}
|
||||
|
||||
data := runtime.Serialize(newCandidates)
|
||||
data := binary.Serialize(newCandidates)
|
||||
storage.Put(ctx, voteKey, data)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue