forked from TrueCloudLab/frostfs-contract
Compare commits
37 commits
support/v0
...
master
Author | SHA1 | Date | |
---|---|---|---|
a1b61d3949 | |||
f28d918727 | |||
7864fc3c4d | |||
edf3c26047 | |||
f30fb324ff | |||
0dda536d4a | |||
43097d2152 | |||
03d0c10852 | |||
21bfe3ebf0 | |||
e56e8d02ee | |||
20f86e96b2 | |||
5cc34f98e9 | |||
dd5919348d | |||
e2e406932f | |||
501b0c5e3c | |||
8affa716e0 | |||
95fe7781d5 | |||
b76f592095 | |||
5cc810096f | |||
c8b14d1376 | |||
edfab37677 | |||
0ea65ca637 | |||
d890a7eba4 | |||
dacac0b53d | |||
6e9c770142 | |||
09281e3ef3 | |||
9ed3845aa9 | |||
901d5a4083 | |||
e09df69ffe | |||
e834a66117 | |||
5124555f05 | |||
184fcdc5a7 | |||
bab6b619d0 | |||
2be81b1def | |||
ab0a899a28 | |||
0b3ea05f76 | |||
c13c01a5c0 |
67 changed files with 9984 additions and 1889 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
name: DCO action
|
||||||
on: [pull_request]
|
on: [pull_request]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
@ -15,6 +16,6 @@ jobs:
|
||||||
go-version: '1.20'
|
go-version: '1.20'
|
||||||
|
|
||||||
- name: Run commit format checker
|
- name: Run commit format checker
|
||||||
uses: https://git.alexvan.in/alexvanin/dco-go@v2
|
uses: https://git.frostfs.info/TrueCloudLab/dco-go@v2
|
||||||
with:
|
with:
|
||||||
from: master
|
from: 'origin/${{ github.event.pull_request.base.ref }}'
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
name: Tests
|
||||||
on: [pull_request]
|
on: [pull_request]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
28
Makefile
28
Makefile
|
@ -22,12 +22,13 @@ all: sidechain mainnet
|
||||||
sidechain: alphabet morph nns
|
sidechain: alphabet morph nns
|
||||||
|
|
||||||
alphabet_sc = alphabet
|
alphabet_sc = alphabet
|
||||||
morph_sc = audit balance container frostfsid netmap proxy reputation
|
morph_sc = balance container frostfsid netmap proxy policy
|
||||||
mainnet_sc = frostfs processing
|
mainnet_sc = frostfs processing
|
||||||
nns_sc = nns
|
nns_sc = nns
|
||||||
|
all_sc = $(alphabet_sc) $(morph_sc) $(mainnet_sc) $(nns_sc)
|
||||||
|
|
||||||
define sc_template
|
define sc_template
|
||||||
$(2)$(1)/$(1)_contract.nef: $(2)$(1)/$(1)_contract.go
|
$(2)$(1)/$(1)_contract.nef: $(2)$(1)/$(1)_contract.go $(2)$(1)/config.yml
|
||||||
$(NEOGO) contract compile -i $(2)$(1) -c $(if $(2),$(2),$(1)/)config.yml -m $(2)$(1)/config.json -o $(2)$(1)/$(1)_contract.nef
|
$(NEOGO) contract compile -i $(2)$(1) -c $(if $(2),$(2),$(1)/)config.yml -m $(2)$(1)/config.json -o $(2)$(1)/$(1)_contract.nef
|
||||||
|
|
||||||
$(if $(2),$(2)$(1)/$(1)_contract.go: alphabet/alphabet.go alphabet/alphabet.tpl
|
$(if $(2),$(2)$(1)/$(1)_contract.go: alphabet/alphabet.go alphabet/alphabet.tpl
|
||||||
|
@ -49,9 +50,32 @@ neo-go:
|
||||||
@go list -f '{{.Path}}/...@{{.Version}}' -m github.com/nspcc-dev/neo-go \
|
@go list -f '{{.Path}}/...@{{.Version}}' -m github.com/nspcc-dev/neo-go \
|
||||||
| xargs go install -v
|
| xargs go install -v
|
||||||
|
|
||||||
|
generate-wrapper.%:
|
||||||
|
@mkdir -p ./rpcclient/$*
|
||||||
|
@# Note, that bindings file is currently missing: is can be emitted by compiler,
|
||||||
|
@# but this leads to a large amount of code duplication. It can be written by hand,
|
||||||
|
@# in case we need to override the type of some variables.
|
||||||
|
@# --config $*/$*.bindings.yml
|
||||||
|
@# Unfortunately, primitive integer types are not yet supported.
|
||||||
|
$(NEOGO) contract generate-rpcwrapper --manifest=$*/config.json --out ./rpcclient/$*/client.go
|
||||||
|
|
||||||
|
generate-wrappers: build $(foreach sc,$(all_sc),generate-wrapper.$(sc))
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@go test ./tests/...
|
@go test ./tests/...
|
||||||
|
|
||||||
|
# Run all code formatters
|
||||||
|
fmts: fumpt imports
|
||||||
|
|
||||||
|
# Reformat imports
|
||||||
|
imports:
|
||||||
|
@echo "⇒ Processing goimports check"
|
||||||
|
@goimports -w $(all_sc) tests/
|
||||||
|
|
||||||
|
fumpt:
|
||||||
|
@echo "⇒ Processing gofumpt check"
|
||||||
|
@gofumpt -l -w $(all_sc) tests/
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
find . -name '*.nef' -exec rm -rf {} \;
|
find . -name '*.nef' -exec rm -rf {} \;
|
||||||
find . -name 'config.json' -exec rm -rf {} \;
|
find . -name 'config.json' -exec rm -rf {} \;
|
||||||
|
|
|
@ -18,38 +18,32 @@ const (
|
||||||
indexKey = "index"
|
indexKey = "index"
|
||||||
totalKey = "threshold"
|
totalKey = "threshold"
|
||||||
nameKey = "name"
|
nameKey = "name"
|
||||||
|
|
||||||
notaryDisabledKey = "notary"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// OnNEP17Payment is a callback for NEP-17 compatible native GAS and NEO
|
// OnNEP17Payment is a callback for NEP-17 compatible native GAS and NEO
|
||||||
// contracts.
|
// contracts.
|
||||||
func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
|
func OnNEP17Payment(from interop.Hash160, amount int, data any) {
|
||||||
caller := runtime.GetCallingScriptHash()
|
caller := runtime.GetCallingScriptHash()
|
||||||
if !common.BytesEqual(caller, []byte(gas.Hash)) && !common.BytesEqual(caller, []byte(neo.Hash)) {
|
if !common.BytesEqual(caller, []byte(gas.Hash)) && !common.BytesEqual(caller, []byte(neo.Hash)) {
|
||||||
common.AbortWithMessage("alphabet contract accepts GAS and NEO only")
|
common.AbortWithMessage("alphabet contract accepts GAS and NEO only")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func _deploy(data interface{}, isUpdate bool) {
|
func _deploy(data any, isUpdate bool) {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
common.RmAndCheckNotaryDisabledKey(data, notaryDisabledKey)
|
|
||||||
|
|
||||||
if isUpdate {
|
if isUpdate {
|
||||||
args := data.([]interface{})
|
args := data.([]any)
|
||||||
common.CheckVersion(args[len(args)-1].(int))
|
common.CheckVersion(args[len(args)-1].(int))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
args := data.(struct {
|
args := data.(struct {
|
||||||
//TODO(@acid-ant): #9 remove notaryDisabled in future version
|
addrNetmap interop.Hash160
|
||||||
notaryDisabled bool
|
addrProxy interop.Hash160
|
||||||
addrNetmap interop.Hash160
|
name string
|
||||||
addrProxy interop.Hash160
|
index int
|
||||||
name string
|
total int
|
||||||
index int
|
|
||||||
total int
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if len(args.addrNetmap) != interop.Hash160Len || len(args.addrProxy) != interop.Hash160Len {
|
if len(args.addrNetmap) != interop.Hash160Len || len(args.addrProxy) != interop.Hash160Len {
|
||||||
|
@ -67,7 +61,7 @@ func _deploy(data interface{}, isUpdate bool) {
|
||||||
|
|
||||||
// Update method updates contract source code and manifest. It can be invoked
|
// Update method updates contract source code and manifest. It can be invoked
|
||||||
// only by committee.
|
// only by committee.
|
||||||
func Update(script []byte, manifest []byte, data interface{}) {
|
func Update(script []byte, manifest []byte, data any) {
|
||||||
if !common.HasUpdateAccess() {
|
if !common.HasUpdateAccess() {
|
||||||
panic("only committee can update contract")
|
panic("only committee can update contract")
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,13 +20,12 @@ Alphabet contract does not produce notifications to process.
|
||||||
|
|
||||||
# Contract storage scheme
|
# Contract storage scheme
|
||||||
|
|
||||||
| Key | Value | Description |
|
| Key | Value | Description |
|
||||||
|--------------------|------------|-------------------------------------------------|
|
|--------------------|------------|-------------------------------------------------|
|
||||||
| `netmapScriptHash` | Hash160 | netmap contract hash |
|
| `netmapScriptHash` | Hash160 | netmap contract hash |
|
||||||
| `proxyScriptHash` | Hash160 | proxy contract hash |
|
| `proxyScriptHash` | Hash160 | proxy contract hash |
|
||||||
| `name` | string | assigned glagolitic letter |
|
| `name` | string | assigned glagolitic letter |
|
||||||
| `index` | int | the index of deployed alphabet contract |
|
| `index` | int | the index of deployed alphabet contract |
|
||||||
| `threshold` | int | the total number of deployed alphabet contracts |
|
| `threshold` | int | the total number of deployed alphabet contracts |
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package alphabet
|
package alphabet
|
||||||
|
|
|
@ -1,226 +0,0 @@
|
||||||
package audit
|
|
||||||
|
|
||||||
import (
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-contract/common"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/iterator"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/crypto"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/management"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
auditHeader struct {
|
|
||||||
epoch int
|
|
||||||
cid []byte
|
|
||||||
from interop.PublicKey
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// Audit key is a combination of the epoch, the container ID and the public key of the node that
|
|
||||||
// has executed the audit. Together, it shouldn't be more than 64 bytes. We can't shrink
|
|
||||||
// epoch and container ID since we iterate over these values. But we can shrink
|
|
||||||
// public key by using first bytes of the hashed value.
|
|
||||||
|
|
||||||
// V2 format
|
|
||||||
const maxKeySize = 24 // 24 + 32 (container ID length) + 8 (epoch length) = 64
|
|
||||||
|
|
||||||
func (a auditHeader) ID() []byte {
|
|
||||||
var buf interface{} = a.epoch
|
|
||||||
|
|
||||||
hashedKey := crypto.Sha256(a.from)
|
|
||||||
shortedKey := hashedKey[:maxKeySize]
|
|
||||||
|
|
||||||
return append(buf.([]byte), append(a.cid, shortedKey...)...)
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
|
||||||
netmapContractKey = "netmapScriptHash"
|
|
||||||
|
|
||||||
notaryDisabledKey = "notary"
|
|
||||||
)
|
|
||||||
|
|
||||||
func _deploy(data interface{}, isUpdate bool) {
|
|
||||||
ctx := storage.GetContext()
|
|
||||||
|
|
||||||
common.RmAndCheckNotaryDisabledKey(data, notaryDisabledKey)
|
|
||||||
|
|
||||||
if isUpdate {
|
|
||||||
args := data.([]interface{})
|
|
||||||
common.CheckVersion(args[len(args)-1].(int))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
args := data.(struct {
|
|
||||||
//TODO(@acid-ant): #9 remove notaryDisabled in future version
|
|
||||||
notaryDisabled bool
|
|
||||||
addrNetmap interop.Hash160
|
|
||||||
})
|
|
||||||
|
|
||||||
if len(args.addrNetmap) != interop.Hash160Len {
|
|
||||||
panic("incorrect length of contract script hash")
|
|
||||||
}
|
|
||||||
|
|
||||||
storage.Put(ctx, netmapContractKey, args.addrNetmap)
|
|
||||||
|
|
||||||
runtime.Log("audit contract initialized")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update method updates contract source code and manifest. It can be invoked
|
|
||||||
// only by committee.
|
|
||||||
func Update(script []byte, manifest []byte, data interface{}) {
|
|
||||||
if !common.HasUpdateAccess() {
|
|
||||||
panic("only committee can update contract")
|
|
||||||
}
|
|
||||||
|
|
||||||
management.UpdateWithData(script, manifest, common.AppendVersion(data))
|
|
||||||
runtime.Log("audit contract updated")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Put method stores a stable marshalled `DataAuditResult` structure. It can be
|
|
||||||
// invoked only by Inner Ring nodes.
|
|
||||||
//
|
|
||||||
// Inner Ring nodes perform audit of containers and produce `DataAuditResult`
|
|
||||||
// structures. They are stored in audit contract and used for settlements
|
|
||||||
// in later epochs.
|
|
||||||
func Put(rawAuditResult []byte) {
|
|
||||||
ctx := storage.GetContext()
|
|
||||||
|
|
||||||
innerRing := common.InnerRingNodes()
|
|
||||||
|
|
||||||
hdr := newAuditHeader(rawAuditResult)
|
|
||||||
presented := false
|
|
||||||
|
|
||||||
for i := range innerRing {
|
|
||||||
ir := innerRing[i]
|
|
||||||
if common.BytesEqual(ir, hdr.from) {
|
|
||||||
presented = true
|
|
||||||
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !runtime.CheckWitness(hdr.from) || !presented {
|
|
||||||
panic("put access denied")
|
|
||||||
}
|
|
||||||
|
|
||||||
storage.Put(ctx, hdr.ID(), rawAuditResult)
|
|
||||||
|
|
||||||
runtime.Log("audit: result has been saved")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get method returns a stable marshaled DataAuditResult structure.
|
|
||||||
//
|
|
||||||
// The ID of the DataAuditResult can be obtained from listing methods.
|
|
||||||
func Get(id []byte) []byte {
|
|
||||||
ctx := storage.GetReadOnlyContext()
|
|
||||||
return storage.Get(ctx, id).([]byte)
|
|
||||||
}
|
|
||||||
|
|
||||||
// List method returns a list of all available DataAuditResult IDs from
|
|
||||||
// the contract storage.
|
|
||||||
func List() [][]byte {
|
|
||||||
ctx := storage.GetReadOnlyContext()
|
|
||||||
it := storage.Find(ctx, []byte{}, storage.KeysOnly)
|
|
||||||
|
|
||||||
return list(it)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListByEpoch method returns a list of DataAuditResult IDs generated during
|
|
||||||
// the specified epoch.
|
|
||||||
func ListByEpoch(epoch int) [][]byte {
|
|
||||||
ctx := storage.GetReadOnlyContext()
|
|
||||||
var buf interface{} = epoch
|
|
||||||
it := storage.Find(ctx, buf.([]byte), storage.KeysOnly)
|
|
||||||
|
|
||||||
return list(it)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListByCID method returns a list of DataAuditResult IDs generated during
|
|
||||||
// the specified epoch for the specified container.
|
|
||||||
func ListByCID(epoch int, cid []byte) [][]byte {
|
|
||||||
ctx := storage.GetReadOnlyContext()
|
|
||||||
|
|
||||||
var buf interface{} = epoch
|
|
||||||
|
|
||||||
prefix := append(buf.([]byte), cid...)
|
|
||||||
it := storage.Find(ctx, prefix, storage.KeysOnly)
|
|
||||||
|
|
||||||
return list(it)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListByNode method returns a list of DataAuditResult IDs generated in
|
|
||||||
// the specified epoch for the specified container by the specified Inner Ring node.
|
|
||||||
func ListByNode(epoch int, cid []byte, key interop.PublicKey) [][]byte {
|
|
||||||
ctx := storage.GetReadOnlyContext()
|
|
||||||
hdr := auditHeader{
|
|
||||||
epoch: epoch,
|
|
||||||
cid: cid,
|
|
||||||
from: key,
|
|
||||||
}
|
|
||||||
|
|
||||||
it := storage.Find(ctx, hdr.ID(), storage.KeysOnly)
|
|
||||||
|
|
||||||
return list(it)
|
|
||||||
}
|
|
||||||
|
|
||||||
func list(it iterator.Iterator) [][]byte {
|
|
||||||
var result [][]byte
|
|
||||||
|
|
||||||
ignore := [][]byte{
|
|
||||||
[]byte(netmapContractKey),
|
|
||||||
}
|
|
||||||
|
|
||||||
loop:
|
|
||||||
for iterator.Next(it) {
|
|
||||||
key := iterator.Value(it).([]byte) // iterator MUST BE `storage.KeysOnly`
|
|
||||||
for _, ignoreKey := range ignore {
|
|
||||||
if common.BytesEqual(key, ignoreKey) {
|
|
||||||
continue loop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result = append(result, key)
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
// Version returns the version of the contract.
|
|
||||||
func Version() int {
|
|
||||||
return common.Version
|
|
||||||
}
|
|
||||||
|
|
||||||
// readNext reads the length from the first byte, and then reads data (max 127 bytes).
|
|
||||||
func readNext(input []byte) ([]byte, int) {
|
|
||||||
var buf interface{} = input[0]
|
|
||||||
ln := buf.(int)
|
|
||||||
|
|
||||||
return input[1 : 1+ln], 1 + ln
|
|
||||||
}
|
|
||||||
|
|
||||||
func newAuditHeader(input []byte) auditHeader {
|
|
||||||
// V2 format
|
|
||||||
offset := int(input[1])
|
|
||||||
offset = 2 + offset + 1 // version prefix + version len + epoch prefix
|
|
||||||
|
|
||||||
var buf interface{} = input[offset : offset+8] // [ 8 integer bytes ]
|
|
||||||
epoch := buf.(int)
|
|
||||||
|
|
||||||
offset = offset + 8
|
|
||||||
|
|
||||||
// cid is a nested structure with raw bytes
|
|
||||||
// [ cid struct prefix (wireType + len = 2 bytes), cid value wireType (1 byte), ... ]
|
|
||||||
cid, cidOffset := readNext(input[offset+2+1:])
|
|
||||||
|
|
||||||
// key is a raw byte
|
|
||||||
// [ public key wireType (1 byte), ... ]
|
|
||||||
key, _ := readNext(input[offset+2+1+cidOffset+1:])
|
|
||||||
|
|
||||||
return auditHeader{
|
|
||||||
epoch,
|
|
||||||
cid,
|
|
||||||
key,
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +0,0 @@
|
||||||
name: "Audit"
|
|
||||||
safemethods: ["get", "list", "listByEpoch", "listByCID", "listByNode", "version"]
|
|
||||||
permissions:
|
|
||||||
- methods: ["update"]
|
|
30
audit/doc.go
30
audit/doc.go
|
@ -1,30 +0,0 @@
|
||||||
/*
|
|
||||||
Audit contract is a contract deployed in FrostFS sidechain.
|
|
||||||
|
|
||||||
Inner Ring nodes perform audit of the registered containers during every epoch.
|
|
||||||
If a container contains StorageGroup objects, an Inner Ring node initializes
|
|
||||||
a series of audit checks. Based on the results of these checks, the Inner Ring
|
|
||||||
node creates a DataAuditResult structure for the container. The content of this
|
|
||||||
structure makes it possible to determine which storage nodes have been examined and
|
|
||||||
see the status of these checks. Regarding this information, the container owner is
|
|
||||||
charged for data storage.
|
|
||||||
|
|
||||||
Audit contract is used as a reliable and verifiable storage for all
|
|
||||||
DataAuditResult structures. At the end of data audit routine, Inner Ring
|
|
||||||
nodes send a stable marshaled version of the DataAuditResult structure to the
|
|
||||||
contract. When Alphabet nodes of the Inner Ring perform settlement operations,
|
|
||||||
they make a list and get these AuditResultStructures from the audit contract.
|
|
||||||
|
|
||||||
# Contract notifications
|
|
||||||
|
|
||||||
Audit contract does not produce notifications to process.
|
|
||||||
|
|
||||||
# Contract storage scheme
|
|
||||||
|
|
||||||
| Key | Value | Description |
|
|
||||||
|--------------------|------------|-----------------------------------------------------------|
|
|
||||||
| `netmapScriptHash` | Hash160 | netmap contract hash |
|
|
||||||
| auditID | ByteArray | serialized DataAuditResult structure |
|
|
||||||
|
|
||||||
*/
|
|
||||||
package audit
|
|
|
@ -31,6 +31,13 @@ type (
|
||||||
// account wasn't burnt.
|
// account wasn't burnt.
|
||||||
Parent []byte
|
Parent []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// account is a stored view of Account with fixed int size
|
||||||
|
account struct {
|
||||||
|
Balance []byte
|
||||||
|
Until []byte
|
||||||
|
Parent []byte
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -40,7 +47,6 @@ const (
|
||||||
|
|
||||||
netmapContractKey = "netmapScriptHash"
|
netmapContractKey = "netmapScriptHash"
|
||||||
containerContractKey = "containerScriptHash"
|
containerContractKey = "containerScriptHash"
|
||||||
notaryDisabledKey = "notary"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var token Token
|
var token Token
|
||||||
|
@ -57,22 +63,18 @@ func init() {
|
||||||
token = createToken()
|
token = createToken()
|
||||||
}
|
}
|
||||||
|
|
||||||
func _deploy(data interface{}, isUpdate bool) {
|
func _deploy(data any, isUpdate bool) {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
common.RmAndCheckNotaryDisabledKey(data, notaryDisabledKey)
|
|
||||||
|
|
||||||
if isUpdate {
|
if isUpdate {
|
||||||
args := data.([]interface{})
|
args := data.([]any)
|
||||||
common.CheckVersion(args[len(args)-1].(int))
|
common.CheckVersion(args[len(args)-1].(int))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
args := data.(struct {
|
args := data.(struct {
|
||||||
//TODO(@acid-ant): #9 remove notaryDisabled in future version
|
addrNetmap interop.Hash160
|
||||||
notaryDisabled bool
|
addrContainer interop.Hash160
|
||||||
addrNetmap interop.Hash160
|
|
||||||
addrContainer interop.Hash160
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if len(args.addrNetmap) != interop.Hash160Len || len(args.addrContainer) != interop.Hash160Len {
|
if len(args.addrNetmap) != interop.Hash160Len || len(args.addrContainer) != interop.Hash160Len {
|
||||||
|
@ -87,7 +89,7 @@ func _deploy(data interface{}, isUpdate bool) {
|
||||||
|
|
||||||
// Update method updates contract source code and manifest. It can be invoked
|
// Update method updates contract source code and manifest. It can be invoked
|
||||||
// only by committee.
|
// only by committee.
|
||||||
func Update(script []byte, manifest []byte, data interface{}) {
|
func Update(script []byte, manifest []byte, data any) {
|
||||||
if !common.HasUpdateAccess() {
|
if !common.HasUpdateAccess() {
|
||||||
panic("only committee can update contract")
|
panic("only committee can update contract")
|
||||||
}
|
}
|
||||||
|
@ -126,7 +128,7 @@ func BalanceOf(account interop.Hash160) int {
|
||||||
//
|
//
|
||||||
// It produces Transfer and TransferX notifications. TransferX notification
|
// It produces Transfer and TransferX notifications. TransferX notification
|
||||||
// will have empty details field.
|
// will have empty details field.
|
||||||
func Transfer(from, to interop.Hash160, amount int, data interface{}) bool {
|
func Transfer(from, to interop.Hash160, amount int, data any) bool {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
return token.transfer(ctx, from, to, amount, false, nil)
|
return token.transfer(ctx, from, to, amount, false, nil)
|
||||||
}
|
}
|
||||||
|
@ -173,7 +175,7 @@ func Lock(txDetails []byte, from, to interop.Hash160, amount, until int) {
|
||||||
Parent: from,
|
Parent: from,
|
||||||
}
|
}
|
||||||
|
|
||||||
common.SetSerialized(ctx, to, lockAccount)
|
setAccount(ctx, to, lockAccount)
|
||||||
|
|
||||||
result := token.transfer(ctx, from, to, amount, true, details)
|
result := token.transfer(ctx, from, to, amount, true, details)
|
||||||
if !result {
|
if !result {
|
||||||
|
@ -310,14 +312,14 @@ func (t Token) transfer(ctx storage.Context, from, to interop.Hash160, amount in
|
||||||
storage.Delete(ctx, from)
|
storage.Delete(ctx, from)
|
||||||
} else {
|
} else {
|
||||||
amountFrom.Balance = amountFrom.Balance - amount // neo-go#953
|
amountFrom.Balance = amountFrom.Balance - amount // neo-go#953
|
||||||
common.SetSerialized(ctx, from, amountFrom)
|
setAccount(ctx, from, amountFrom)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(to) == 20 {
|
if len(to) == 20 {
|
||||||
amountTo := getAccount(ctx, to)
|
amountTo := getAccount(ctx, to)
|
||||||
amountTo.Balance = amountTo.Balance + amount // neo-go#953
|
amountTo.Balance = amountTo.Balance + amount // neo-go#953
|
||||||
common.SetSerialized(ctx, to, amountTo)
|
setAccount(ctx, to, amountTo)
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime.Notify("Transfer", from, to, amount)
|
runtime.Notify("Transfer", from, to, amount)
|
||||||
|
@ -328,9 +330,7 @@ func (t Token) transfer(ctx storage.Context, from, to interop.Hash160, amount in
|
||||||
|
|
||||||
// canTransfer returns the amount it can transfer.
|
// canTransfer returns the amount it can transfer.
|
||||||
func (t Token) canTransfer(ctx storage.Context, from, to interop.Hash160, amount int, innerRing bool) (Account, bool) {
|
func (t Token) canTransfer(ctx storage.Context, from, to interop.Hash160, amount int, innerRing bool) (Account, bool) {
|
||||||
var (
|
emptyAcc := Account{}
|
||||||
emptyAcc = Account{}
|
|
||||||
)
|
|
||||||
|
|
||||||
if !innerRing {
|
if !innerRing {
|
||||||
if len(to) != interop.Hash160Len || !isUsableAddress(from) {
|
if len(to) != interop.Hash160Len || !isUsableAddress(from) {
|
||||||
|
@ -368,11 +368,24 @@ func isUsableAddress(addr interop.Hash160) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAccount(ctx storage.Context, key interface{}) Account {
|
func getAccount(ctx storage.Context, key any) Account {
|
||||||
data := storage.Get(ctx, key)
|
data := storage.Get(ctx, key)
|
||||||
if data != nil {
|
if data != nil {
|
||||||
return std.Deserialize(data.([]byte)).(Account)
|
acc := std.Deserialize(data.([]byte)).(account)
|
||||||
|
return Account{
|
||||||
|
Balance: common.FromFixedWidth64(acc.Balance),
|
||||||
|
Until: common.FromFixedWidth64(acc.Until),
|
||||||
|
Parent: acc.Parent,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Account{}
|
return Account{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setAccount(ctx storage.Context, key any, acc Account) {
|
||||||
|
common.SetSerialized(ctx, key, account{
|
||||||
|
Balance: common.ToFixedWidth64(acc.Balance),
|
||||||
|
Until: common.ToFixedWidth64(acc.Until),
|
||||||
|
Parent: acc.Parent,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -77,11 +77,10 @@ when FrostFS contract has transferred GAS assets back to the user.
|
||||||
|
|
||||||
# Contract storage scheme
|
# Contract storage scheme
|
||||||
|
|
||||||
| Key | Value | Description |
|
| Key | Value | Description |
|
||||||
|-----------------------|------------|----------------------------------|
|
|-----------------------|------------|----------------------------------|
|
||||||
| `netmapScriptHash` | Hash160 | netmap contract hash |
|
| `netmapScriptHash` | Hash160 | netmap contract hash |
|
||||||
| `containerScriptHash` | Hash160 | container contract hash |
|
| `containerScriptHash` | Hash160 | container contract hash |
|
||||||
| circulationKey | int | the token circulation key value |
|
| circulationKey | int | the token circulation key value |
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package balance
|
package balance
|
||||||
|
|
|
@ -1,26 +1,11 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/util"
|
"github.com/nspcc-dev/neo-go/pkg/interop/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
panicMsgForNotaryDisabledEnv = "contract not applicable for notary-disabled environment"
|
|
||||||
)
|
|
||||||
|
|
||||||
// BytesEqual compares two slices of bytes by wrapping them into strings,
|
// BytesEqual compares two slices of bytes by wrapping them into strings,
|
||||||
// which is necessary with new util.Equals interop behaviour, see neo-go#1176.
|
// which is necessary with new util.Equals interop behaviour, see neo-go#1176.
|
||||||
func BytesEqual(a []byte, b []byte) bool {
|
func BytesEqual(a []byte, b []byte) bool {
|
||||||
return util.Equals(string(a), string(b))
|
return util.Equals(string(a), string(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
// RmAndCheckNotaryDisabledKey remove notary disabled key from storage and
|
|
||||||
// panic in notary disabled environment
|
|
||||||
func RmAndCheckNotaryDisabledKey(data interface{}, key interface{}) {
|
|
||||||
//TODO(@acid-ant): #9 remove notaryDisabled from args in future version
|
|
||||||
storage.Delete(storage.GetContext(), key)
|
|
||||||
if data.([]interface{})[0].(bool) {
|
|
||||||
panic(panicMsgForNotaryDisabledEnv)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,12 +1,28 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/interop/convert"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/std"
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/std"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetSerialized serializes data and puts it into contract storage.
|
// SetSerialized serializes data and puts it into contract storage.
|
||||||
func SetSerialized(ctx storage.Context, key interface{}, value interface{}) {
|
func SetSerialized(ctx storage.Context, key any, value interface{}) {
|
||||||
data := std.Serialize(value)
|
data := std.Serialize(value)
|
||||||
storage.Put(ctx, key, data)
|
storage.Put(ctx, key, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToFixedWidth64 converts x to bytes such that numbers <= math.MaxUint64
|
||||||
|
// have constant with of 9.
|
||||||
|
func ToFixedWidth64(x int) []byte {
|
||||||
|
data := convert.ToBytes(x)
|
||||||
|
if x < 0 || len(data) >= 9 {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
return append(data, make([]byte, 9-len(data))...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromFixedWidth64 is a reverse function for ToFixedWidth64.
|
||||||
|
func FromFixedWidth64(x []byte) int {
|
||||||
|
return convert.ToInteger(x)
|
||||||
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ func LockTransferDetails(txDetails []byte) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func UnlockTransferDetails(epoch int) []byte {
|
func UnlockTransferDetails(epoch int) []byte {
|
||||||
var buf interface{} = epoch
|
var buf any = epoch
|
||||||
return append(unlockPrefix, buf.([]byte)...)
|
return append(unlockPrefix, buf.([]byte)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,9 +38,9 @@ func CheckVersion(from int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppendVersion appends current contract version to the list of deploy arguments.
|
// AppendVersion appends current contract version to the list of deploy arguments.
|
||||||
func AppendVersion(data interface{}) []interface{} {
|
func AppendVersion(data any) []interface{} {
|
||||||
if data == nil {
|
if data == nil {
|
||||||
return []interface{}{Version}
|
return []any{Version}
|
||||||
}
|
}
|
||||||
return append(data.([]interface{}), Version)
|
return append(data.([]any), Version)
|
||||||
}
|
}
|
||||||
|
|
20
commonclient/invoker.go
Normal file
20
commonclient/invoker.go
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package commonclient
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"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/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Invoker is a subset of methods provided by struct invoker.Invoker. The subset contains only those
|
||||||
|
// methods that are used by ActorWrapper and clients of the contracts.
|
||||||
|
type Invoker interface {
|
||||||
|
Call(contract util.Uint160, method string, params ...any) (*result.Invoke, error)
|
||||||
|
TraverseIterator(sessionID uuid.UUID, iterator *result.Iterator, num int) ([]stackitem.Item, error)
|
||||||
|
TerminateSession(sessionID uuid.UUID) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure the interface is compatible with the invoker.Invoker struct.
|
||||||
|
var _ Invoker = (*invoker.Invoker)(nil)
|
35
commonclient/iterator.go
Normal file
35
commonclient/iterator.go
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
package commonclient
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ReadIteratorItems calls method that returns iterator and traverses the iterator until all items are read into array.
|
||||||
|
func ReadIteratorItems(inv Invoker, batchSize int, contract util.Uint160, method string, params ...any) ([]stackitem.Item, error) {
|
||||||
|
if batchSize <= 0 {
|
||||||
|
panic("batch size must be positive")
|
||||||
|
}
|
||||||
|
|
||||||
|
sessionID, iter, err := unwrap.SessionIterator(inv.Call(contract, method, params...))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unwrap session iterator: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var shouldStop bool
|
||||||
|
res := make([]stackitem.Item, 0, len(iter.Values))
|
||||||
|
for !shouldStop {
|
||||||
|
items, err := inv.TraverseIterator(sessionID, &iter, batchSize)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
res = append(res, items...)
|
||||||
|
shouldStop = len(items) < batchSize
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
63
commonclient/transaction.go
Normal file
63
commonclient/transaction.go
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
package commonclient
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Transaction allows to invoke several contract method at once.
|
||||||
|
type Transaction struct {
|
||||||
|
writer *io.BufBinWriter
|
||||||
|
buffer *io.BufBinWriter
|
||||||
|
contract util.Uint160
|
||||||
|
}
|
||||||
|
|
||||||
|
var ErrTransactionTooLarge = errors.New("transaction/script size limit exceeded")
|
||||||
|
|
||||||
|
// NewTransaction creates new transaction to accumulate contract invocations.
|
||||||
|
func NewTransaction(contractHash util.Uint160) *Transaction {
|
||||||
|
return &Transaction{
|
||||||
|
writer: io.NewBufBinWriter(),
|
||||||
|
buffer: io.NewBufBinWriter(),
|
||||||
|
contract: contractHash,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WrapCall accept methods and arguments to invoke.
|
||||||
|
// Should be used with method on clients like Client.MethodNameCall.
|
||||||
|
func (t Transaction) WrapCall(method string, args []any) error {
|
||||||
|
t.buffer.Reset()
|
||||||
|
emit.AppCall(t.buffer.BinWriter, t.contract, method, callflag.All, args...)
|
||||||
|
|
||||||
|
if t.writer.Len()+t.buffer.Len() > transaction.MaxScriptLength {
|
||||||
|
return ErrTransactionTooLarge
|
||||||
|
}
|
||||||
|
|
||||||
|
t.writer.WriteBytes(t.buffer.Bytes())
|
||||||
|
|
||||||
|
return t.writer.Err
|
||||||
|
}
|
||||||
|
|
||||||
|
// WrapCallErr accept methods, arguments and error to handle and invoke.
|
||||||
|
// Should be used with method on clients like *CallErr.
|
||||||
|
func (t Transaction) WrapCallErr(method string, args []any, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.WrapCall(method, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bytes returns the resulting buffer and makes future writes return an error.
|
||||||
|
func (t Transaction) Bytes() ([]byte, error) {
|
||||||
|
if t.writer.Len() > transaction.MaxScriptLength {
|
||||||
|
return nil, ErrTransactionTooLarge
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.writer.Bytes(), nil
|
||||||
|
}
|
|
@ -13,7 +13,6 @@ safemethods:
|
||||||
- "version"
|
- "version"
|
||||||
permissions:
|
permissions:
|
||||||
- methods:
|
- methods:
|
||||||
- "addKey"
|
|
||||||
- "addRecord"
|
- "addRecord"
|
||||||
- "deleteRecords"
|
- "deleteRecords"
|
||||||
- "register"
|
- "register"
|
||||||
|
|
|
@ -50,7 +50,6 @@ const (
|
||||||
nnsContractKey = "nnsScriptHash"
|
nnsContractKey = "nnsScriptHash"
|
||||||
nnsRootKey = "nnsRoot"
|
nnsRootKey = "nnsRoot"
|
||||||
nnsHasAliasKey = "nnsHasAlias"
|
nnsHasAliasKey = "nnsHasAlias"
|
||||||
notaryDisabledKey = "notary"
|
|
||||||
|
|
||||||
// RegistrationFeeKey is a key in netmap config which contains fee for container registration.
|
// RegistrationFeeKey is a key in netmap config which contains fee for container registration.
|
||||||
RegistrationFeeKey = "ContainerFee"
|
RegistrationFeeKey = "ContainerFee"
|
||||||
|
@ -83,21 +82,17 @@ const (
|
||||||
defaultTTL = 3600 // 1 hour
|
defaultTTL = 3600 // 1 hour
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var eACLPrefix = []byte("eACL")
|
||||||
eACLPrefix = []byte("eACL")
|
|
||||||
)
|
|
||||||
|
|
||||||
// OnNEP11Payment is needed for registration with contract as the owner to work.
|
// OnNEP11Payment is needed for registration with contract as the owner to work.
|
||||||
func OnNEP11Payment(a interop.Hash160, b int, c []byte, d interface{}) {
|
func OnNEP11Payment(a interop.Hash160, b int, c []byte, d any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func _deploy(data interface{}, isUpdate bool) {
|
func _deploy(data any, isUpdate bool) {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
common.RmAndCheckNotaryDisabledKey(data, notaryDisabledKey)
|
|
||||||
|
|
||||||
if isUpdate {
|
if isUpdate {
|
||||||
args := data.([]interface{})
|
args := data.([]any)
|
||||||
common.CheckVersion(args[len(args)-1].(int))
|
common.CheckVersion(args[len(args)-1].(int))
|
||||||
|
|
||||||
it := storage.Find(ctx, []byte{}, storage.None)
|
it := storage.Find(ctx, []byte{}, storage.None)
|
||||||
|
@ -123,13 +118,11 @@ func _deploy(data interface{}, isUpdate bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
args := data.(struct {
|
args := data.(struct {
|
||||||
//TODO(@acid-ant): #9 remove notaryDisabled in future version
|
addrNetmap interop.Hash160
|
||||||
notaryDisabled bool
|
addrBalance interop.Hash160
|
||||||
addrNetmap interop.Hash160
|
addrID interop.Hash160
|
||||||
addrBalance interop.Hash160
|
addrNNS interop.Hash160
|
||||||
addrID interop.Hash160
|
nnsRoot string
|
||||||
addrNNS interop.Hash160
|
|
||||||
nnsRoot string
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if len(args.addrNetmap) != interop.Hash160Len ||
|
if len(args.addrNetmap) != interop.Hash160Len ||
|
||||||
|
@ -167,7 +160,7 @@ func registerNiceNameTLD(addrNNS interop.Hash160, nnsRoot string) {
|
||||||
|
|
||||||
// Update method updates contract source code and manifest. It can be invoked
|
// Update method updates contract source code and manifest. It can be invoked
|
||||||
// by committee only.
|
// by committee only.
|
||||||
func Update(script []byte, manifest []byte, data interface{}) {
|
func Update(script []byte, manifest []byte, data any) {
|
||||||
if !common.HasUpdateAccess() {
|
if !common.HasUpdateAccess() {
|
||||||
panic("only committee can update contract")
|
panic("only committee can update contract")
|
||||||
}
|
}
|
||||||
|
@ -192,12 +185,12 @@ func Put(container []byte, signature interop.Signature, publicKey interop.Public
|
||||||
// Note that zone must exist.
|
// Note that zone must exist.
|
||||||
func PutNamed(container []byte, signature interop.Signature,
|
func PutNamed(container []byte, signature interop.Signature,
|
||||||
publicKey interop.PublicKey, token []byte,
|
publicKey interop.PublicKey, token []byte,
|
||||||
name, zone string) {
|
name, zone string,
|
||||||
|
) {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
ownerID := ownerFromBinaryContainer(container)
|
ownerID := ownerFromBinaryContainer(container)
|
||||||
containerID := crypto.Sha256(container)
|
containerID := crypto.Sha256(container)
|
||||||
frostfsIDContractAddr := storage.Get(ctx, frostfsIDContractKey).(interop.Hash160)
|
|
||||||
cnr := Container{
|
cnr := Container{
|
||||||
value: container,
|
value: container,
|
||||||
sig: signature,
|
sig: signature,
|
||||||
|
@ -270,10 +263,6 @@ func PutNamed(container []byte, signature interop.Signature,
|
||||||
storage.Put(ctx, key, domain)
|
storage.Put(ctx, key, domain)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(token) == 0 { // if container created directly without session
|
|
||||||
contract.Call(frostfsIDContractAddr, "addKey", contract.All, ownerID, [][]byte{publicKey})
|
|
||||||
}
|
|
||||||
|
|
||||||
runtime.Log("added new container")
|
runtime.Log("added new container")
|
||||||
runtime.Notify("PutSuccess", containerID, publicKey)
|
runtime.Notify("PutSuccess", containerID, publicKey)
|
||||||
}
|
}
|
||||||
|
@ -329,7 +318,7 @@ func Delete(containerID []byte, signature interop.Signature, publicKey interop.P
|
||||||
// and inability to delete a container. We should also check if we own the record in case.
|
// and inability to delete a container. We should also check if we own the record in case.
|
||||||
nnsContractAddr := storage.Get(ctx, nnsContractKey).(interop.Hash160)
|
nnsContractAddr := storage.Get(ctx, nnsContractKey).(interop.Hash160)
|
||||||
res := contract.Call(nnsContractAddr, "getRecords", contract.ReadStates|contract.AllowCall, domain, 16 /* TXT */)
|
res := contract.Call(nnsContractAddr, "getRecords", contract.ReadStates|contract.AllowCall, domain, 16 /* TXT */)
|
||||||
if res != nil && std.Base58Encode(containerID) == string(res.([]interface{})[0].(string)) {
|
if res != nil && std.Base58Encode(containerID) == string(res.([]any)[0].(string)) {
|
||||||
contract.Call(nnsContractAddr, "deleteRecords", contract.All, domain, 16 /* TXT */)
|
contract.Call(nnsContractAddr, "deleteRecords", contract.All, domain, 16 /* TXT */)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -343,6 +332,11 @@ type DelInfo struct {
|
||||||
Epoch int
|
Epoch int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type delInfo struct {
|
||||||
|
Owner []byte
|
||||||
|
Epoch []byte
|
||||||
|
}
|
||||||
|
|
||||||
// DeletionInfo method returns container deletion info.
|
// DeletionInfo method returns container deletion info.
|
||||||
// If the container had never existed, NotFoundError is throwed.
|
// If the container had never existed, NotFoundError is throwed.
|
||||||
// It can be used to check whether non-existing container was indeed deleted
|
// It can be used to check whether non-existing container was indeed deleted
|
||||||
|
@ -354,7 +348,12 @@ func DeletionInfo(containerID []byte) DelInfo {
|
||||||
if data == nil {
|
if data == nil {
|
||||||
panic(NotFoundError)
|
panic(NotFoundError)
|
||||||
}
|
}
|
||||||
return std.Deserialize(data).(DelInfo)
|
|
||||||
|
d := std.Deserialize(data).(delInfo)
|
||||||
|
return DelInfo{
|
||||||
|
Owner: d.Owner,
|
||||||
|
Epoch: common.FromFixedWidth64(d.Epoch),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get method returns a structure that contains a stable marshaled Container structure,
|
// Get method returns a structure that contains a stable marshaled Container structure,
|
||||||
|
@ -536,7 +535,7 @@ func GetContainerSize(id []byte) containerSizes {
|
||||||
func ListContainerSizes(epoch int) [][]byte {
|
func ListContainerSizes(epoch int) [][]byte {
|
||||||
ctx := storage.GetReadOnlyContext()
|
ctx := storage.GetReadOnlyContext()
|
||||||
|
|
||||||
var buf interface{} = epoch
|
var buf any = epoch
|
||||||
|
|
||||||
key := []byte(estimateKeyPrefix)
|
key := []byte(estimateKeyPrefix)
|
||||||
key = append(key, buf.([]byte)...)
|
key = append(key, buf.([]byte)...)
|
||||||
|
@ -568,7 +567,7 @@ func ListContainerSizes(epoch int) [][]byte {
|
||||||
func IterateContainerSizes(epoch int) iterator.Iterator {
|
func IterateContainerSizes(epoch int) iterator.Iterator {
|
||||||
ctx := storage.GetReadOnlyContext()
|
ctx := storage.GetReadOnlyContext()
|
||||||
|
|
||||||
var buf interface{} = epoch
|
var buf any = epoch
|
||||||
|
|
||||||
key := []byte(estimateKeyPrefix)
|
key := []byte(estimateKeyPrefix)
|
||||||
key = append(key, buf.([]byte)...)
|
key = append(key, buf.([]byte)...)
|
||||||
|
@ -631,9 +630,9 @@ func removeContainer(ctx storage.Context, id []byte, owner []byte) {
|
||||||
graveKey := append([]byte{graveKeyPrefix}, id...)
|
graveKey := append([]byte{graveKeyPrefix}, id...)
|
||||||
netmapContractAddr := storage.Get(ctx, netmapContractKey).(interop.Hash160)
|
netmapContractAddr := storage.Get(ctx, netmapContractKey).(interop.Hash160)
|
||||||
epoch := contract.Call(netmapContractAddr, "epoch", contract.ReadOnly).(int)
|
epoch := contract.Call(netmapContractAddr, "epoch", contract.ReadOnly).(int)
|
||||||
common.SetSerialized(ctx, graveKey, DelInfo{
|
common.SetSerialized(ctx, graveKey, delInfo{
|
||||||
Owner: owner,
|
Owner: owner,
|
||||||
Epoch: epoch,
|
Epoch: common.ToFixedWidth64(epoch),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -686,7 +685,7 @@ func ownerFromBinaryContainer(container []byte) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func estimationKey(epoch int, cid []byte, key interop.PublicKey) []byte {
|
func estimationKey(epoch int, cid []byte, key interop.PublicKey) []byte {
|
||||||
var buf interface{} = epoch
|
var buf any = epoch
|
||||||
|
|
||||||
hash := crypto.Ripemd160(key)
|
hash := crypto.Ripemd160(key)
|
||||||
|
|
||||||
|
@ -764,7 +763,7 @@ func cleanupContainers(ctx storage.Context, epoch int) {
|
||||||
// V2 format
|
// V2 format
|
||||||
nbytes := k[len(estimateKeyPrefix) : len(k)-containerIDSize-estimatePostfixSize]
|
nbytes := k[len(estimateKeyPrefix) : len(k)-containerIDSize-estimatePostfixSize]
|
||||||
|
|
||||||
var n interface{} = nbytes
|
var n any = nbytes
|
||||||
|
|
||||||
if epoch-n.(int) > TotalCleanupDelta {
|
if epoch-n.(int) > TotalCleanupDelta {
|
||||||
storage.Delete(ctx, k)
|
storage.Delete(ctx, k)
|
||||||
|
|
|
@ -26,19 +26,17 @@ it in Container contract.
|
||||||
|
|
||||||
# Contract storage scheme
|
# Contract storage scheme
|
||||||
|
|
||||||
| Key | Value | Description |
|
| Key | Value | Description |
|
||||||
|-----------------------------------------------------------------------------------------------------|
|
|-----------------------------------------------------------------------------------------------------|
|
||||||
| `netmapScriptHash` | Hash160 | netmap contract hash |
|
| `netmapScriptHash` | Hash160 | netmap contract hash |
|
||||||
| `balanceScriptHash` | Hash160 | balance contract hash |
|
| `balanceScriptHash` | Hash160 | balance contract hash |
|
||||||
| `identityScriptHash` | Hash160 | frostfsID contract hash |
|
| `identityScriptHash` | Hash160 | frostfsID contract hash |
|
||||||
| `nnsContractKey` | Hash160 | nns contract hash |
|
| `nnsContractKey` | Hash160 | nns contract hash |
|
||||||
| `nnsRoot` | string | default value for domain zone |
|
| `nnsRoot` | string | default value for domain zone |
|
||||||
| `cnr` + epoch + containerID + publicKeyHash[:10] | ByteArray | estimated container size |
|
| `cnr` + epoch + containerID + publicKeyHash[:10] | ByteArray | estimated container size |
|
||||||
| `est` + containerID + publicKeyHash | ByteArray | serialized epochs array |
|
| `est` + containerID + publicKeyHash | ByteArray | serialized epochs array |
|
||||||
| `o` + ownerID + containerID | ByteArray | container ID |
|
| `o` + ownerID + containerID | ByteArray | container ID |
|
||||||
| `x` + containerID | ByteArray | serialized container struct |
|
| `x` + containerID | ByteArray | serialized container struct |
|
||||||
| `nnsHasAlias` + containerID | string | domain name |
|
| `nnsHasAlias` + containerID | string | domain name |
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package container
|
package container
|
||||||
|
|
|
@ -83,12 +83,10 @@ FrostFS network configuration value.
|
||||||
|
|
||||||
# Contract storage scheme
|
# Contract storage scheme
|
||||||
|
|
||||||
| Key | Value | Description |
|
| Key | Value | Description |
|
||||||
|-----------------------------------------------------------------------------|
|
|-----------------------------------------------------------------------------|
|
||||||
| `processingScriptHash` | Hash160 | processing contract hash |
|
| `processingScriptHash` | Hash160 | processing contract hash |
|
||||||
| `candidates` + candidateKey | ByteArray | it flags inner ring candidate |
|
| `candidates` + candidateKey | ByteArray | it flags inner ring candidate |
|
||||||
| `config` + postfix | ByteArray | serialized config data |
|
| `config` + postfix | ByteArray | serialized config data |
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package frostfs
|
package frostfs
|
||||||
|
|
|
@ -26,9 +26,8 @@ const (
|
||||||
CandidateFeeConfigKey = "InnerRingCandidateFee"
|
CandidateFeeConfigKey = "InnerRingCandidateFee"
|
||||||
withdrawFeeConfigKey = "WithdrawFee"
|
withdrawFeeConfigKey = "WithdrawFee"
|
||||||
|
|
||||||
alphabetKey = "alphabet"
|
alphabetKey = "alphabet"
|
||||||
candidatesKey = "candidates"
|
candidatesKey = "candidates"
|
||||||
notaryDisabledKey = "notary"
|
|
||||||
|
|
||||||
processingContractKey = "processingScriptHash"
|
processingContractKey = "processingScriptHash"
|
||||||
|
|
||||||
|
@ -39,28 +38,22 @@ const (
|
||||||
ignoreDepositNotification = "\x57\x0b"
|
ignoreDepositNotification = "\x57\x0b"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var configPrefix = []byte("config")
|
||||||
configPrefix = []byte("config")
|
|
||||||
)
|
|
||||||
|
|
||||||
// _deploy sets up initial alphabet node keys.
|
// _deploy sets up initial alphabet node keys.
|
||||||
func _deploy(data interface{}, isUpdate bool) {
|
func _deploy(data any, isUpdate bool) {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
common.RmAndCheckNotaryDisabledKey(data, notaryDisabledKey)
|
|
||||||
|
|
||||||
if isUpdate {
|
if isUpdate {
|
||||||
args := data.([]interface{})
|
args := data.([]any)
|
||||||
common.CheckVersion(args[len(args)-1].(int))
|
common.CheckVersion(args[len(args)-1].(int))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
args := data.(struct {
|
args := data.(struct {
|
||||||
//TODO(@acid-ant): #9 remove notaryDisabled in future version
|
addrProc interop.Hash160
|
||||||
notaryDisabled bool
|
keys []interop.PublicKey
|
||||||
addrProc interop.Hash160
|
config [][]byte
|
||||||
keys []interop.PublicKey
|
|
||||||
config [][]byte
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if len(args.keys) == 0 {
|
if len(args.keys) == 0 {
|
||||||
|
@ -100,7 +93,7 @@ func _deploy(data interface{}, isUpdate bool) {
|
||||||
|
|
||||||
// Update method updates contract source code and manifest. It can be invoked
|
// Update method updates contract source code and manifest. It can be invoked
|
||||||
// only by sidechain committee.
|
// only by sidechain committee.
|
||||||
func Update(script []byte, manifest []byte, data interface{}) {
|
func Update(script []byte, manifest []byte, data any) {
|
||||||
blockHeight := ledger.CurrentIndex()
|
blockHeight := ledger.CurrentIndex()
|
||||||
alphabetKeys := roles.GetDesignatedByRole(roles.NeoFSAlphabet, uint32(blockHeight+1))
|
alphabetKeys := roles.GetDesignatedByRole(roles.NeoFSAlphabet, uint32(blockHeight+1))
|
||||||
alphabetCommittee := common.Multiaddress(alphabetKeys, true)
|
alphabetCommittee := common.Multiaddress(alphabetKeys, true)
|
||||||
|
@ -190,7 +183,7 @@ func InnerRingCandidateAdd(key interop.PublicKey) {
|
||||||
// It takes no more than 9000.0 GAS. Native GAS has precision 8, and
|
// It takes no more than 9000.0 GAS. Native GAS has precision 8, and
|
||||||
// FrostFS balance contract has precision 12. Values bigger than 9000.0 can
|
// FrostFS balance contract has precision 12. Values bigger than 9000.0 can
|
||||||
// break JSON limits for integers when precision is converted.
|
// break JSON limits for integers when precision is converted.
|
||||||
func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
|
func OnNEP17Payment(from interop.Hash160, amount int, data any) {
|
||||||
rcv := data.(interop.Hash160)
|
rcv := data.(interop.Hash160)
|
||||||
if common.BytesEqual(rcv, []byte(ignoreDepositNotification)) {
|
if common.BytesEqual(rcv, []byte(ignoreDepositNotification)) {
|
||||||
return
|
return
|
||||||
|
@ -321,7 +314,7 @@ func Unbind(user []byte, keys []interop.PublicKey) {
|
||||||
|
|
||||||
// Config returns configuration value of FrostFS configuration. If the key does
|
// Config returns configuration value of FrostFS configuration. If the key does
|
||||||
// not exists, returns nil.
|
// not exists, returns nil.
|
||||||
func Config(key []byte) interface{} {
|
func Config(key []byte) any {
|
||||||
ctx := storage.GetReadOnlyContext()
|
ctx := storage.GetReadOnlyContext()
|
||||||
return getConfig(ctx, key)
|
return getConfig(ctx, key)
|
||||||
}
|
}
|
||||||
|
@ -376,7 +369,7 @@ func getAlphabetNodes(ctx storage.Context) []interop.PublicKey {
|
||||||
}
|
}
|
||||||
|
|
||||||
// getConfig returns the installed frostfs configuration value or nil if it is not set.
|
// getConfig returns the installed frostfs configuration value or nil if it is not set.
|
||||||
func getConfig(ctx storage.Context, key interface{}) interface{} {
|
func getConfig(ctx storage.Context, key any) interface{} {
|
||||||
postfix := key.([]byte)
|
postfix := key.([]byte)
|
||||||
storageKey := append(configPrefix, postfix...)
|
storageKey := append(configPrefix, postfix...)
|
||||||
|
|
||||||
|
@ -384,7 +377,7 @@ func getConfig(ctx storage.Context, key interface{}) interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
// setConfig sets a frostfs configuration value in the contract storage.
|
// setConfig sets a frostfs configuration value in the contract storage.
|
||||||
func setConfig(ctx storage.Context, key, val interface{}) {
|
func setConfig(ctx storage.Context, key, val any) {
|
||||||
postfix := key.([]byte)
|
postfix := key.([]byte)
|
||||||
storageKey := append(configPrefix, postfix...)
|
storageKey := append(configPrefix, postfix...)
|
||||||
|
|
||||||
|
|
880
frostfsid/client/client.go
Normal file
880
frostfsid/client/client.go
Normal file
|
@ -0,0 +1,880 @@
|
||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-contract/commonclient"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
Client struct {
|
||||||
|
act *actor.Actor
|
||||||
|
acc *wallet.Account
|
||||||
|
contract util.Uint160
|
||||||
|
}
|
||||||
|
|
||||||
|
Options struct {
|
||||||
|
// todo add proxy params
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
Subject struct {
|
||||||
|
PrimaryKey *keys.PublicKey
|
||||||
|
AdditionalKeys keys.PublicKeys
|
||||||
|
Namespace string
|
||||||
|
Name string
|
||||||
|
KV map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
SubjectExtended struct {
|
||||||
|
PrimaryKey *keys.PublicKey
|
||||||
|
AdditionalKeys keys.PublicKeys
|
||||||
|
Namespace string
|
||||||
|
Name string
|
||||||
|
KV map[string]string
|
||||||
|
Groups []*Group
|
||||||
|
}
|
||||||
|
|
||||||
|
Namespace struct {
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
NamespaceExtended struct {
|
||||||
|
Name string
|
||||||
|
GroupsCount int64
|
||||||
|
SubjectsCount int64
|
||||||
|
}
|
||||||
|
|
||||||
|
Group struct {
|
||||||
|
ID int64
|
||||||
|
Name string
|
||||||
|
Namespace string
|
||||||
|
KV map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
GroupExtended struct {
|
||||||
|
ID int64
|
||||||
|
Name string
|
||||||
|
Namespace string
|
||||||
|
KV map[string]string
|
||||||
|
SubjectsCount int64
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
IAMPathKey = "iam-path"
|
||||||
|
IAMARNKey = "iam-arn"
|
||||||
|
IAMCreatedTimeKey = "ctime"
|
||||||
|
IAMModifiedTimeKey = "mtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
const iteratorBatchSize = 100
|
||||||
|
|
||||||
|
const (
|
||||||
|
getAdminMethod = "getAdmin"
|
||||||
|
setAdminMethod = "setAdmin"
|
||||||
|
clearAdminMethod = "clearAdmin"
|
||||||
|
|
||||||
|
versionMethod = "version"
|
||||||
|
|
||||||
|
createSubjectMethod = "createSubject"
|
||||||
|
getSubjectMethod = "getSubject"
|
||||||
|
getSubjectExtendedMethod = "getSubjectExtended"
|
||||||
|
listSubjectsMethod = "listSubjects"
|
||||||
|
addSubjectKeyMethod = "addSubjectKey"
|
||||||
|
removeSubjectKeyMethod = "removeSubjectKey"
|
||||||
|
getSubjectByKeyMethod = "getSubjectByKey"
|
||||||
|
getSubjectKeyByNameMethod = "getSubjectKeyByName"
|
||||||
|
setSubjectKVMethod = "setSubjectKV"
|
||||||
|
setSubjectNameMethod = "setSubjectName"
|
||||||
|
deleteSubjectKVMethod = "deleteSubjectKV"
|
||||||
|
deleteSubjectMethod = "deleteSubject"
|
||||||
|
|
||||||
|
createNamespaceMethod = "createNamespace"
|
||||||
|
getNamespaceMethod = "getNamespace"
|
||||||
|
getNamespaceExtendedMethod = "getNamespaceExtended"
|
||||||
|
listNamespacesMethod = "listNamespaces"
|
||||||
|
addSubjectToNamespaceMethod = "addSubjectToNamespace"
|
||||||
|
removeSubjectFromNamespaceMethod = "removeSubjectFromNamespace"
|
||||||
|
listNamespaceSubjectsMethod = "listNamespaceSubjects"
|
||||||
|
|
||||||
|
createGroupMethod = "createGroup"
|
||||||
|
getGroupMethod = "getGroup"
|
||||||
|
getGroupExtendedMethod = "getGroupExtended"
|
||||||
|
getGroupIDByNameMethod = "getGroupIDByName"
|
||||||
|
setGroupNameMethod = "setGroupName"
|
||||||
|
setGroupKVMethod = "setGroupKV"
|
||||||
|
deleteGroupKVMethod = "deleteGroupKV"
|
||||||
|
listGroupsMethod = "listGroups"
|
||||||
|
addSubjectToGroupMethod = "addSubjectToGroup"
|
||||||
|
removeSubjectFromGroupMethod = "removeSubjectFromGroup"
|
||||||
|
listGroupSubjectsMethod = "listGroupSubjects"
|
||||||
|
deleteGroupMethod = "deleteGroup"
|
||||||
|
)
|
||||||
|
|
||||||
|
// New creates a new Client. Options can be nil.
|
||||||
|
func New(ra actor.RPCActor, acc *wallet.Account, contract util.Uint160, _ *Options) (*Client, error) {
|
||||||
|
act, err := actor.NewSimple(ra, acc)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("init actor: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Client{
|
||||||
|
act: act,
|
||||||
|
acc: acc,
|
||||||
|
contract: contract,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// StartTx inits transaction.
|
||||||
|
func (c Client) StartTx() *commonclient.Transaction {
|
||||||
|
return commonclient.NewTransaction(c.contract)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendTx sends provided transaction to blockchain.
|
||||||
|
func (c Client) SendTx(txn *commonclient.Transaction) (tx util.Uint256, vub uint32, err error) {
|
||||||
|
txBytes, err := txn.Bytes()
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint256{}, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.act.SendRun(txBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Version returns version of contract.
|
||||||
|
func (c Client) Version() (int64, error) {
|
||||||
|
return unwrap.Int64(c.act.Call(c.contract, versionMethod))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAdmin sets address that can perform write operations on contract.
|
||||||
|
// Must be invoked by committee.
|
||||||
|
func (c Client) SetAdmin(owner util.Uint160) (tx util.Uint256, vub uint32, err error) {
|
||||||
|
method, args := c.SetAdminCall(owner)
|
||||||
|
return c.act.SendCall(c.contract, method, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAdminCall provides args for SetAdmin to use in commonclient.Transaction.
|
||||||
|
func (c Client) SetAdminCall(owner util.Uint160) (method string, args []any) {
|
||||||
|
return setAdminMethod, []any{owner}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearAdmin removes address that can perform write operations on contract.
|
||||||
|
// Must be invoked by committee.
|
||||||
|
func (c Client) ClearAdmin() (tx util.Uint256, vub uint32, err error) {
|
||||||
|
method, args := c.ClearAdminCall()
|
||||||
|
return c.act.SendCall(c.contract, method, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearAdminCall provides args for ClearAdmin to use in commonclient.Transaction.
|
||||||
|
func (c Client) ClearAdminCall() (method string, args []any) {
|
||||||
|
return clearAdminMethod, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAdmin returns address that can perform write operations on contract.
|
||||||
|
// Second return values is true iff admin is set.
|
||||||
|
func (c Client) GetAdmin() (util.Uint160, bool, error) {
|
||||||
|
item, err := unwrap.Item(c.act.Call(c.contract, getAdminMethod))
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, false, err
|
||||||
|
}
|
||||||
|
if item.Value() == nil {
|
||||||
|
return util.Uint160{}, false, nil
|
||||||
|
}
|
||||||
|
bs, err := item.TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, true, err
|
||||||
|
}
|
||||||
|
u, err := util.Uint160DecodeBytesBE(bs)
|
||||||
|
return u, true, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateSubject creates new subject using public key.
|
||||||
|
// Must be invoked by contract owner.
|
||||||
|
func (c Client) CreateSubject(key *keys.PublicKey) (tx util.Uint256, vub uint32, err error) {
|
||||||
|
method, args := c.CreateSubjectCall(key)
|
||||||
|
return c.act.SendCall(c.contract, method, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateSubjectCall provides args for CreateSubject to use in commonclient.Transaction.
|
||||||
|
func (c Client) CreateSubjectCall(key *keys.PublicKey) (method string, args []any) {
|
||||||
|
return createSubjectMethod, []any{key.Bytes()}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSubject gets subject by address.
|
||||||
|
func (c Client) GetSubject(addr util.Uint160) (*Subject, error) {
|
||||||
|
items, err := unwrap.Array(c.act.Call(c.contract, getSubjectMethod, addr))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseSubject(items)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSubjectExtended gets extended subject by address.
|
||||||
|
func (c Client) GetSubjectExtended(addr util.Uint160) (*SubjectExtended, error) {
|
||||||
|
items, err := unwrap.Array(c.act.Call(c.contract, getSubjectExtendedMethod, addr))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseSubjectExtended(items)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListSubjects gets all subjects.
|
||||||
|
func (c Client) ListSubjects() ([]util.Uint160, error) {
|
||||||
|
return unwrapArrayOfUint160(commonclient.ReadIteratorItems(c.act, iteratorBatchSize, c.contract, listSubjectsMethod))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddSubjectKey adds extra public key to subject.
|
||||||
|
// Must be invoked by contract owner.
|
||||||
|
func (c Client) AddSubjectKey(addr util.Uint160, key *keys.PublicKey) (tx util.Uint256, vub uint32, err error) {
|
||||||
|
method, args := c.AddSubjectKeyCall(addr, key)
|
||||||
|
return c.act.SendCall(c.contract, method, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddSubjectKeyCall provides args for AddSubjectKey to use in commonclient.Transaction.
|
||||||
|
func (c Client) AddSubjectKeyCall(addr util.Uint160, key *keys.PublicKey) (method string, args []any) {
|
||||||
|
return addSubjectKeyMethod, []any{addr, key.Bytes()}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveSubjectKey removes extra public key from subject.
|
||||||
|
// Must be invoked by contract owner.
|
||||||
|
func (c Client) RemoveSubjectKey(addr util.Uint160, key *keys.PublicKey) (tx util.Uint256, vub uint32, err error) {
|
||||||
|
method, args := c.RemoveSubjectKeyCall(addr, key)
|
||||||
|
return c.act.SendCall(c.contract, method, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveSubjectKeyCall provides args for RemoveSubjectKey to use in commonclient.Transaction.
|
||||||
|
func (c Client) RemoveSubjectKeyCall(addr util.Uint160, key *keys.PublicKey) (method string, args []any) {
|
||||||
|
return removeSubjectKeyMethod, []any{addr, key.Bytes()}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSubjectKV updates subject kv map.
|
||||||
|
// Must be invoked by contract owner.
|
||||||
|
// You can use some predefined key constants: IAMPathKey, IAMARNKey, IAMCreatedTimeKey, IAMModifiedTimeKey.
|
||||||
|
func (c Client) SetSubjectKV(addr util.Uint160, key, val string) (tx util.Uint256, vub uint32, err error) {
|
||||||
|
method, args := c.SetSubjectKVCall(addr, key, val)
|
||||||
|
return c.act.SendCall(c.contract, method, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSubjectKVCall provides args for SetSubjectKV to use in commonclient.Transaction.
|
||||||
|
func (c Client) SetSubjectKVCall(addr util.Uint160, key, val string) (method string, args []any) {
|
||||||
|
return setSubjectKVMethod, []any{addr, key, val}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSubjectName updates subject name.
|
||||||
|
// Must be invoked by contract owner.
|
||||||
|
func (c Client) SetSubjectName(addr util.Uint160, name string) (tx util.Uint256, vub uint32, err error) {
|
||||||
|
method, args := c.SetSubjectNameCall(addr, name)
|
||||||
|
return c.act.SendCall(c.contract, method, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSubjectNameCall provides args for SetSubjectName to use in commonclient.Transaction.
|
||||||
|
func (c Client) SetSubjectNameCall(addr util.Uint160, name string) (method string, args []any) {
|
||||||
|
return setSubjectNameMethod, []any{addr, name}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteSubjectKV removes subject kv map.
|
||||||
|
// Must be invoked by contract owner.
|
||||||
|
func (c Client) DeleteSubjectKV(addr util.Uint160, key string) (tx util.Uint256, vub uint32, err error) {
|
||||||
|
method, args := c.DeleteSubjectKVCall(addr, key)
|
||||||
|
return c.act.SendCall(c.contract, method, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteSubjectKVCall provides args for DeleteSubjectKV to use in commonclient.Transaction.
|
||||||
|
func (c Client) DeleteSubjectKVCall(addr util.Uint160, key string) (method string, args []any) {
|
||||||
|
return deleteSubjectKVMethod, []any{addr, key}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSubjectByKey gets subject by its primary or additional keys.
|
||||||
|
func (c Client) GetSubjectByKey(key *keys.PublicKey) (*Subject, error) {
|
||||||
|
items, err := unwrap.Array(c.act.Call(c.contract, getSubjectByKeyMethod, key.Bytes()))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseSubject(items)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSubjectKeyByName gets subject public key by its name (namespace scope).
|
||||||
|
func (c Client) GetSubjectKeyByName(namespace, subjectName string) (*keys.PublicKey, error) {
|
||||||
|
return unwrap.PublicKey(c.act.Call(c.contract, getSubjectKeyByNameMethod, namespace, subjectName))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteSubject delete subject and removes it from related namespaces and groups.
|
||||||
|
// Must be invoked by contract owner.
|
||||||
|
func (c Client) DeleteSubject(addr util.Uint160) (tx util.Uint256, vub uint32, err error) {
|
||||||
|
method, args := c.DeleteSubjectCall(addr)
|
||||||
|
return c.act.SendCall(c.contract, method, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteSubjectCall provides args for DeleteSubject to use in commonclient.Transaction.
|
||||||
|
func (c Client) DeleteSubjectCall(addr util.Uint160) (method string, args []any) {
|
||||||
|
return deleteSubjectMethod, []any{addr}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateNamespace create new namespace.
|
||||||
|
// Must be invoked by contract owner.
|
||||||
|
func (c Client) CreateNamespace(namespace string) (tx util.Uint256, vub uint32, err error) {
|
||||||
|
method, args := c.CreateNamespaceCall(namespace)
|
||||||
|
return c.act.SendCall(c.contract, method, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateNamespaceCall provides args for CreateNamespace to use in commonclient.Transaction.
|
||||||
|
func (c Client) CreateNamespaceCall(namespace string) (method string, args []any) {
|
||||||
|
return createNamespaceMethod, []any{namespace}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetNamespace gets namespace.
|
||||||
|
func (c Client) GetNamespace(namespace string) (*Namespace, error) {
|
||||||
|
items, err := unwrap.Array(c.act.Call(c.contract, getNamespaceMethod, namespace))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseNamespace(items)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetNamespaceExtended gets extended namespace.
|
||||||
|
func (c Client) GetNamespaceExtended(namespace string) (*NamespaceExtended, error) {
|
||||||
|
items, err := unwrap.Array(c.act.Call(c.contract, getNamespaceExtendedMethod, namespace))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseNamespaceExtended(items)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListNamespaces gets all namespaces.
|
||||||
|
func (c Client) ListNamespaces() ([]*Namespace, error) {
|
||||||
|
items, err := commonclient.ReadIteratorItems(c.act, iteratorBatchSize, c.contract, listNamespacesMethod)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseNamespaces(items)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddSubjectToNamespace adds a subject to namespace.
|
||||||
|
// Must be invoked by contract owner.
|
||||||
|
func (c Client) AddSubjectToNamespace(addr util.Uint160, namespace string) (tx util.Uint256, vub uint32, err error) {
|
||||||
|
method, args := c.AddSubjectToNamespaceCall(addr, namespace)
|
||||||
|
return c.act.SendCall(c.contract, method, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddSubjectToNamespaceCall provides args for AddSubjectToNamespace to use in commonclient.Transaction.
|
||||||
|
func (c Client) AddSubjectToNamespaceCall(addr util.Uint160, namespace string) (method string, args []any) {
|
||||||
|
return addSubjectToNamespaceMethod, []any{addr, namespace}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveSubjectFromNamespace removes a subject from namespace.
|
||||||
|
// Must be invoked by contract owner.
|
||||||
|
func (c Client) RemoveSubjectFromNamespace(addr util.Uint160) (tx util.Uint256, vub uint32, err error) {
|
||||||
|
method, args := c.RemoveSubjectFromNamespaceCall(addr)
|
||||||
|
return c.act.SendCall(c.contract, method, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveSubjectFromNamespaceCall provides args for RemoveSubjectFromNamespace to use in commonclient.Transaction.
|
||||||
|
func (c Client) RemoveSubjectFromNamespaceCall(addr util.Uint160) (method string, args []any) {
|
||||||
|
return removeSubjectFromNamespaceMethod, []any{addr}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListNamespaceSubjects gets all subjects from namespace.
|
||||||
|
func (c Client) ListNamespaceSubjects(namespace string) ([]util.Uint160, error) {
|
||||||
|
return unwrapArrayOfUint160(commonclient.ReadIteratorItems(c.act, iteratorBatchSize, c.contract, listNamespaceSubjectsMethod, namespace))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateGroup creates a new group in specific namespace.
|
||||||
|
// Must be invoked by contract owner.
|
||||||
|
func (c Client) CreateGroup(namespace, group string) (tx util.Uint256, vub uint32, err error) {
|
||||||
|
method, args := c.CreateGroupCall(namespace, group)
|
||||||
|
return c.act.SendCall(c.contract, method, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateGroupCall provides args for CreateGroup to use in commonclient.Transaction.
|
||||||
|
func (c Client) CreateGroupCall(namespace, group string) (method string, args []any) {
|
||||||
|
return createGroupMethod, []any{namespace, group}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGroup gets group.
|
||||||
|
func (c Client) GetGroup(namespace string, groupID int64) (*Group, error) {
|
||||||
|
items, err := unwrap.Array(c.act.Call(c.contract, getGroupMethod, namespace, groupID))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseGroup(items)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGroupExtended gets extended group.
|
||||||
|
func (c Client) GetGroupExtended(namespace string, groupID int64) (*GroupExtended, error) {
|
||||||
|
items, err := unwrap.Array(c.act.Call(c.contract, getGroupExtendedMethod, namespace, groupID))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseGroupExtended(items)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGroupName updates subject name.
|
||||||
|
// Must be invoked by contract owner.
|
||||||
|
func (c Client) SetGroupName(namespace string, groupID int64, name string) (tx util.Uint256, vub uint32, err error) {
|
||||||
|
method, args := c.SetGroupNameCall(namespace, groupID, name)
|
||||||
|
return c.act.SendCall(c.contract, method, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGroupNameCall provides args for SetGroupName to use in commonclient.Transaction.
|
||||||
|
func (c Client) SetGroupNameCall(namespace string, groupID int64, name string) (method string, args []any) {
|
||||||
|
return setGroupNameMethod, []any{namespace, groupID, name}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGroupKV updates group kv map.
|
||||||
|
// Must be invoked by contract owner.
|
||||||
|
// You can use some predefined key constants: IAMPathKey, IAMARNKey, IAMCreatedTimeKey, IAMModifiedTimeKey.
|
||||||
|
func (c Client) SetGroupKV(namespace string, groupID int64, key, val string) (tx util.Uint256, vub uint32, err error) {
|
||||||
|
method, args := c.SetGroupKVCall(namespace, groupID, key, val)
|
||||||
|
return c.act.SendCall(c.contract, method, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGroupKVCall provides args for SetGroupKV to use in commonclient.Transaction.
|
||||||
|
func (c Client) SetGroupKVCall(namespace string, groupID int64, key, val string) (method string, args []any) {
|
||||||
|
return setGroupKVMethod, []any{namespace, groupID, key, val}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteGroupKV removes group kv map.
|
||||||
|
// Must be invoked by contract owner.
|
||||||
|
func (c Client) DeleteGroupKV(namespace string, groupID int64, key string) (tx util.Uint256, vub uint32, err error) {
|
||||||
|
method, args := c.DeleteGroupKVCall(namespace, groupID, key)
|
||||||
|
return c.act.SendCall(c.contract, method, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteGroupKVCall provides args for DeleteGroupKV to use in commonclient.Transaction.
|
||||||
|
func (c Client) DeleteGroupKVCall(namespace string, groupID int64, key string) (method string, args []any) {
|
||||||
|
return deleteGroupKVMethod, []any{namespace, groupID, key}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGroupIDByName gets group id its name (namespace scope).
|
||||||
|
func (c Client) GetGroupIDByName(namespace, groupName string) (int64, error) {
|
||||||
|
return unwrap.Int64(c.act.Call(c.contract, getGroupIDByNameMethod, namespace, groupName))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListGroups gets all groups in specific namespace.
|
||||||
|
func (c Client) ListGroups(namespace string) ([]*Group, error) {
|
||||||
|
items, err := commonclient.ReadIteratorItems(c.act, iteratorBatchSize, c.contract, listGroupsMethod, namespace)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseGroups(items)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddSubjectToGroup adds a new subject to group.
|
||||||
|
// Must be invoked by contract owner.
|
||||||
|
func (c Client) AddSubjectToGroup(addr util.Uint160, groupID int64) (tx util.Uint256, vub uint32, err error) {
|
||||||
|
method, args := c.AddSubjectToGroupCall(addr, groupID)
|
||||||
|
return c.act.SendCall(c.contract, method, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddSubjectToGroupCall provides args for AddSubjectToGroup to use in commonclient.Transaction.
|
||||||
|
func (c Client) AddSubjectToGroupCall(addr util.Uint160, groupID int64) (method string, args []any) {
|
||||||
|
return addSubjectToGroupMethod, []any{addr, groupID}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveSubjectFromGroup removes subject from group.
|
||||||
|
// Must be invoked by contract owner.
|
||||||
|
func (c Client) RemoveSubjectFromGroup(addr util.Uint160, groupID int64) (tx util.Uint256, vub uint32, err error) {
|
||||||
|
method, args := c.RemoveSubjectFromGroupCall(addr, groupID)
|
||||||
|
return c.act.SendCall(c.contract, method, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveSubjectFromGroupCall provides args for RemoveSubjectFromGroup to use in commonclient.Transaction.
|
||||||
|
func (c Client) RemoveSubjectFromGroupCall(addr util.Uint160, groupID int64) (method string, args []any) {
|
||||||
|
return removeSubjectFromGroupMethod, []any{addr, groupID}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListGroupSubjects gets all subjects in specific group.
|
||||||
|
func (c Client) ListGroupSubjects(namespace string, groupID int64) ([]util.Uint160, error) {
|
||||||
|
return unwrapArrayOfUint160(commonclient.ReadIteratorItems(c.act, iteratorBatchSize, c.contract, listGroupSubjectsMethod, namespace, groupID))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteGroup deletes group.
|
||||||
|
// Must be invoked by contract owner.
|
||||||
|
func (c Client) DeleteGroup(namespace string, groupID int64) (tx util.Uint256, vub uint32, err error) {
|
||||||
|
method, args := c.DeleteGroupCall(namespace, groupID)
|
||||||
|
return c.act.SendCall(c.contract, method, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteGroupCall provides args for DeleteGroup to use in commonclient.Transaction.
|
||||||
|
func (c Client) DeleteGroupCall(namespace string, groupID int64) (method string, args []any) {
|
||||||
|
return deleteGroupMethod, []any{namespace, groupID}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListNonEmptyNamespaces gets namespaces that contain at least one subject.
|
||||||
|
func (c Client) ListNonEmptyNamespaces() ([]string, error) {
|
||||||
|
namespaces, err := c.ListNamespaces()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var res []string
|
||||||
|
|
||||||
|
for _, namespace := range namespaces {
|
||||||
|
nsExt, err := c.GetNamespaceExtended(namespace.Name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if nsExt.SubjectsCount > 0 {
|
||||||
|
res = append(res, nsExt.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait invokes underlying wait method on actor.Actor.
|
||||||
|
func (c Client) Wait(tx util.Uint256, vub uint32, err error) (*state.AppExecResult, error) {
|
||||||
|
return c.act.Wait(tx, vub, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParseGroupID fetch groupID from stack after creating group method invocation.
|
||||||
|
func (c Client) ParseGroupID(res *state.AppExecResult, err error) (int64, error) {
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return unwrap.Int64(makeResFromAppExec(res))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListNonEmptyGroups gets groups that contain at least one subject.
|
||||||
|
func (c Client) ListNonEmptyGroups(namespace string) ([]string, error) {
|
||||||
|
groups, err := c.ListGroups(namespace)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var res []string
|
||||||
|
|
||||||
|
for _, group := range groups {
|
||||||
|
groupExt, err := c.GetGroupExtended(namespace, group.ID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if groupExt.SubjectsCount > 0 {
|
||||||
|
res = append(res, groupExt.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func unwrapArrayOfUint160(items []stackitem.Item, err error) ([]util.Uint160, error) {
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return unwrap.ArrayOfUint160(makeValidRes(stackitem.NewArray(items)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeValidRes(item stackitem.Item) (*result.Invoke, error) {
|
||||||
|
return &result.Invoke{
|
||||||
|
Stack: []stackitem.Item{item},
|
||||||
|
State: vmstate.Halt.String(),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeResFromAppExec(res *state.AppExecResult) (*result.Invoke, error) {
|
||||||
|
return &result.Invoke{
|
||||||
|
Stack: res.Stack,
|
||||||
|
State: res.VMState.String(),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseSubject(structArr []stackitem.Item) (*Subject, error) {
|
||||||
|
if len(structArr) < 5 {
|
||||||
|
return nil, errors.New("invalid response subject struct")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
subj Subject
|
||||||
|
)
|
||||||
|
|
||||||
|
subj.PrimaryKey, err = unwrap.PublicKey(makeValidRes(structArr[0]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !structArr[1].Equals(stackitem.Null{}) {
|
||||||
|
subj.AdditionalKeys, err = unwrap.ArrayOfPublicKeys(makeValidRes(structArr[1]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !structArr[2].Equals(stackitem.Null{}) {
|
||||||
|
subj.Namespace, err = unwrap.UTF8String(makeValidRes(structArr[2]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !structArr[2].Equals(stackitem.Null{}) {
|
||||||
|
subj.Name, err = unwrap.UTF8String(makeValidRes(structArr[3]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
subj.KV, err = parseMap(structArr[4])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &subj, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseSubjectExtended(structArr []stackitem.Item) (*SubjectExtended, error) {
|
||||||
|
if len(structArr) < 6 {
|
||||||
|
return nil, errors.New("invalid response subject extended struct")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
subj SubjectExtended
|
||||||
|
)
|
||||||
|
|
||||||
|
subj.PrimaryKey, err = unwrap.PublicKey(makeValidRes(structArr[0]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !structArr[1].Equals(stackitem.Null{}) {
|
||||||
|
subj.AdditionalKeys, err = unwrap.ArrayOfPublicKeys(makeValidRes(structArr[1]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nsBytes, err := structArr[2].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
subj.Namespace = string(nsBytes)
|
||||||
|
|
||||||
|
nameBytes, err := structArr[3].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
subj.Name = string(nameBytes)
|
||||||
|
|
||||||
|
subj.KV, err = parseMap(structArr[4])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !structArr[5].Equals(stackitem.Null{}) {
|
||||||
|
groupItems, ok := structArr[5].Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("invalid groups field")
|
||||||
|
}
|
||||||
|
|
||||||
|
subj.Groups, err = parseGroups(groupItems)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &subj, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseMap(item stackitem.Item) (map[string]string, error) {
|
||||||
|
if item.Equals(stackitem.Null{}) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
metaMap, err := unwrap.Map(makeValidRes(item))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
meta, ok := metaMap.Value().([]stackitem.MapElement)
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("invalid map type")
|
||||||
|
}
|
||||||
|
|
||||||
|
res := make(map[string]string, len(meta))
|
||||||
|
for _, element := range meta {
|
||||||
|
key, err := element.Key.TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
val, err := element.Value.TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
res[string(key)] = string(val)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseNamespace(structArr []stackitem.Item) (*Namespace, error) {
|
||||||
|
if len(structArr) < 1 {
|
||||||
|
return nil, errors.New("invalid response namespace struct")
|
||||||
|
}
|
||||||
|
|
||||||
|
name, err := structArr[0].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Namespace{Name: string(name)}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseNamespaceExtended(structArr []stackitem.Item) (*NamespaceExtended, error) {
|
||||||
|
if len(structArr) < 3 {
|
||||||
|
return nil, errors.New("invalid response namespace extended struct")
|
||||||
|
}
|
||||||
|
|
||||||
|
name, err := structArr[0].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
groupCount, err := structArr[1].TryInteger()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
subjectCount, err := structArr[2].TryInteger()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &NamespaceExtended{
|
||||||
|
Name: string(name),
|
||||||
|
GroupsCount: groupCount.Int64(),
|
||||||
|
SubjectsCount: subjectCount.Int64(),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseNamespaces(items []stackitem.Item) ([]*Namespace, error) {
|
||||||
|
var err error
|
||||||
|
res := make([]*Namespace, len(items))
|
||||||
|
|
||||||
|
for i := 0; i < len(items); i++ {
|
||||||
|
arr, ok := items[i].Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("invalid namespace type")
|
||||||
|
}
|
||||||
|
res[i], err = parseNamespace(arr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseGroup(structArr []stackitem.Item) (*Group, error) {
|
||||||
|
if len(structArr) < 4 {
|
||||||
|
return nil, errors.New("invalid response group struct")
|
||||||
|
}
|
||||||
|
|
||||||
|
groupID, err := structArr[0].TryInteger()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
name, err := structArr[1].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace, err := structArr[2].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
kvs, err := parseMap(structArr[3])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Group{
|
||||||
|
ID: groupID.Int64(),
|
||||||
|
Name: string(name),
|
||||||
|
Namespace: string(namespace),
|
||||||
|
KV: kvs,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseGroupExtended(structArr []stackitem.Item) (*GroupExtended, error) {
|
||||||
|
if len(structArr) < 5 {
|
||||||
|
return nil, errors.New("invalid response group extended struct")
|
||||||
|
}
|
||||||
|
|
||||||
|
groupID, err := structArr[0].TryInteger()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
name, err := structArr[1].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace, err := structArr[2].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
kvs, err := parseMap(structArr[3])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
subjectCount, err := structArr[4].TryInteger()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &GroupExtended{
|
||||||
|
ID: groupID.Int64(),
|
||||||
|
Name: string(name),
|
||||||
|
Namespace: string(namespace),
|
||||||
|
KV: kvs,
|
||||||
|
SubjectsCount: subjectCount.Int64(),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseGroups(items []stackitem.Item) ([]*Group, error) {
|
||||||
|
var err error
|
||||||
|
res := make([]*Group, len(items))
|
||||||
|
|
||||||
|
for i := 0; i < len(items); i++ {
|
||||||
|
arr, ok := items[i].Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("invalid group type")
|
||||||
|
}
|
||||||
|
res[i], err = parseGroup(arr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
|
@ -1,4 +1,131 @@
|
||||||
name: "Identity"
|
name: "Identity"
|
||||||
safemethods: ["key", "version"]
|
safemethods:
|
||||||
|
- "getAdmin"
|
||||||
|
- "getGroup"
|
||||||
|
- "getGroupExtended"
|
||||||
|
- "getGroupIDByName"
|
||||||
|
- "getNamespace"
|
||||||
|
- "getNamespaceExtended"
|
||||||
|
- "getSubject"
|
||||||
|
- "getSubjectExtended"
|
||||||
|
- "getSubjectByKey"
|
||||||
|
- "getSubjectKeyByName"
|
||||||
|
- "listGroups"
|
||||||
|
- "listGroupSubjects"
|
||||||
|
- "listNamespaces"
|
||||||
|
- "listNamespaceSubjects"
|
||||||
|
- "listSubjects"
|
||||||
|
- "version"
|
||||||
permissions:
|
permissions:
|
||||||
- methods: ["update"]
|
- methods: ["update"]
|
||||||
|
events:
|
||||||
|
- name: CreateSubject
|
||||||
|
parameters:
|
||||||
|
- name: subjectAddress
|
||||||
|
type: Hash160
|
||||||
|
- name: AddSubjectKey
|
||||||
|
parameters:
|
||||||
|
- name: subjectAddress
|
||||||
|
type: Hash160
|
||||||
|
- name: subjectKey
|
||||||
|
type: PublicKey
|
||||||
|
- name: RemoveSubjectKey
|
||||||
|
parameters:
|
||||||
|
- name: subjectAddress
|
||||||
|
type: Hash160
|
||||||
|
- name: subjectKey
|
||||||
|
type: PublicKey
|
||||||
|
- name: SetSubjectName
|
||||||
|
parameters:
|
||||||
|
- name: subjectAddress
|
||||||
|
type: Hash160
|
||||||
|
- name: name
|
||||||
|
type: String
|
||||||
|
- name: SetSubjectKV
|
||||||
|
parameters:
|
||||||
|
- name: subjectAddress
|
||||||
|
type: Hash160
|
||||||
|
- name: key
|
||||||
|
type: String
|
||||||
|
- name: value
|
||||||
|
type: String
|
||||||
|
- name: DeleteSubjectKV
|
||||||
|
parameters:
|
||||||
|
- name: subjectAddress
|
||||||
|
type: Hash160
|
||||||
|
- name: key
|
||||||
|
type: String
|
||||||
|
- name: DeleteSubject
|
||||||
|
parameters:
|
||||||
|
- name: subjectAddress
|
||||||
|
type: Hash160
|
||||||
|
- name: CreateNamespace
|
||||||
|
parameters:
|
||||||
|
- name: namespace
|
||||||
|
type: String
|
||||||
|
- name: AddSubjectToNamespace
|
||||||
|
parameters:
|
||||||
|
- name: subjectAddress
|
||||||
|
type: Hash160
|
||||||
|
- name: namespace
|
||||||
|
type: String
|
||||||
|
- name: RemoveSubjectFromNamespace
|
||||||
|
parameters:
|
||||||
|
- name: subjectAddress
|
||||||
|
type: Hash160
|
||||||
|
- name: namespace
|
||||||
|
type: String
|
||||||
|
- name: CreateGroup
|
||||||
|
parameters:
|
||||||
|
- name: namespace
|
||||||
|
type: String
|
||||||
|
- name: group
|
||||||
|
type: String
|
||||||
|
- name: SetGroupName
|
||||||
|
parameters:
|
||||||
|
- name: namespace
|
||||||
|
type: String
|
||||||
|
- name: groupID
|
||||||
|
type: Integer
|
||||||
|
- name: name
|
||||||
|
type: String
|
||||||
|
- name: SetGroupKV
|
||||||
|
parameters:
|
||||||
|
- name: namespace
|
||||||
|
type: String
|
||||||
|
- name: groupID
|
||||||
|
type: Integer
|
||||||
|
- name: key
|
||||||
|
type: String
|
||||||
|
- name: value
|
||||||
|
type: String
|
||||||
|
- name: DeleteGroupKV
|
||||||
|
parameters:
|
||||||
|
- name: namespace
|
||||||
|
type: String
|
||||||
|
- name: groupID
|
||||||
|
type: Integer
|
||||||
|
- name: key
|
||||||
|
type: String
|
||||||
|
- name: AddSubjectToGroup
|
||||||
|
parameters:
|
||||||
|
- name: subjectAddress
|
||||||
|
type: Hash160
|
||||||
|
- name: namespace
|
||||||
|
type: String
|
||||||
|
- name: groupID
|
||||||
|
type: Integer
|
||||||
|
- name: RemoveSubjectFromGroup
|
||||||
|
parameters:
|
||||||
|
- name: subjectAddress
|
||||||
|
type: Hash160
|
||||||
|
- name: namespace
|
||||||
|
type: String
|
||||||
|
- name: groupID
|
||||||
|
type: Integer
|
||||||
|
- name: DeleteGroup
|
||||||
|
parameters:
|
||||||
|
- name: namespace
|
||||||
|
type: String
|
||||||
|
- name: groupID
|
||||||
|
type: Integer
|
||||||
|
|
|
@ -1,29 +1,26 @@
|
||||||
|
// Package frostfsid
|
||||||
/*
|
/*
|
||||||
FrostFSID contract is a contract deployed in FrostFS sidechain.
|
FrostFSID contract is a contract deployed in FrostFS sidechain.
|
||||||
|
|
||||||
FrostFSID contract is used to store connection between an OwnerID and its public keys.
|
|
||||||
OwnerID is a 25-byte N3 wallet address that can be produced from a public key.
|
|
||||||
It is one-way conversion. In simple cases, FrostFS verifies ownership by checking
|
|
||||||
signature and relation between a public key and an OwnerID.
|
|
||||||
|
|
||||||
In more complex cases, a user can use public keys unrelated to the OwnerID to maintain
|
|
||||||
secure access to the data. FrostFSID contract stores relation between an OwnerID and
|
|
||||||
arbitrary public keys. Data owner can bind a public key with its account or unbind it
|
|
||||||
by invoking Bind or Unbind methods of FrostFS contract in the mainchain. After that,
|
|
||||||
Alphabet nodes produce multisigned AddKey and RemoveKey invocations of FrostFSID
|
|
||||||
contract.
|
|
||||||
|
|
||||||
# Contract notifications
|
# Contract notifications
|
||||||
|
|
||||||
FrostFSID contract does not produce notifications to process.
|
FrostFSID contract does not produce notifications to process.
|
||||||
|
|
||||||
# Contract storage scheme
|
# Contract storage scheme
|
||||||
|
|
||||||
| Key | Value | Description |
|
| Key | Value | Description |
|
||||||
|-----------------------------|------------|----------------------------------|
|
|------------------------------------------------------------------------------|--------------------------------|-----------------------------------------------|
|
||||||
| `processingScriptHash` | Hash160 | netmap contract hash |
|
| `o` + [ owner address ] | []byte{1} | contract owners that can invoke write methods |
|
||||||
| `containerScriptHash` | Hash160 | container contract hash |
|
| `s` + [ subject address ] | Serialized Subject structure | subject into |
|
||||||
| `o` + ownerID + publicKey | ByteArray | it flags owner's public key |
|
| `a` + [ pk address ] + [ subject address ] | []byte{1} | link extra public keys for subject |
|
||||||
|
| `n` + [ RIPEMD160 of namespace ] | Serialized Namespace structure | namespace info |
|
||||||
|
| `N` + [ RIPEMD160 of namespace ] + [ subject address ] | []byte{1} | subject that belongs to the namespace |
|
||||||
|
| `l` + [ RIPEMD160 of namespace ] + [ RIPEMD160 of subject name ] | Subject public key | subject name to public key index |
|
||||||
|
| `g` + [ RIPEMD160 of namespace ] + [ 8 byte group id ] | Serialized Group structure | group into |
|
||||||
|
| `G` + [ RIPEMD160 of namespace ] + [ 8 byte group id ] + [ subject address ] | []byte{1} | subject that belongs to the group |
|
||||||
|
| `c` | Int | group id counter |
|
||||||
|
| `m` + [ RIPEMD160 of namespace ] + [ RIPEMD160 of subject name ] | Serialized group id int | group name to group id index |
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package frostfsid
|
package frostfsid
|
||||||
|
|
File diff suppressed because it is too large
Load diff
58
go.mod
58
go.mod
|
@ -1,10 +1,60 @@
|
||||||
module git.frostfs.info/TrueCloudLab/frostfs-contract
|
module git.frostfs.info/TrueCloudLab/frostfs-contract
|
||||||
|
|
||||||
go 1.14
|
go 1.20
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/google/uuid v1.3.0
|
||||||
github.com/mr-tron/base58 v1.2.0
|
github.com/mr-tron/base58 v1.2.0
|
||||||
github.com/nspcc-dev/neo-go v0.101.5-0.20230808195420-5fc61be5f6c5
|
github.com/nspcc-dev/neo-go v0.103.0
|
||||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230808195420-5fc61be5f6c5
|
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231020160724-c3955f87d1b5
|
||||||
github.com/stretchr/testify v1.8.1
|
github.com/stretchr/testify v1.8.4
|
||||||
|
go.uber.org/zap v1.26.0
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
|
github.com/bits-and-blooms/bitset v1.8.0 // indirect
|
||||||
|
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||||
|
github.com/consensys/bavard v0.1.13 // indirect
|
||||||
|
github.com/consensys/gnark-crypto v0.12.2-0.20231013160410-1f65e75b6dfb // indirect
|
||||||
|
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
|
||||||
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
|
||||||
|
github.com/golang/protobuf v1.5.3 // indirect
|
||||||
|
github.com/golang/snappy v0.0.1 // indirect
|
||||||
|
github.com/google/go-cmp v0.5.9 // indirect
|
||||||
|
github.com/gorilla/websocket v1.4.2 // indirect
|
||||||
|
github.com/hashicorp/golang-lru v0.6.0 // indirect
|
||||||
|
github.com/holiman/uint256 v1.2.0 // indirect
|
||||||
|
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
|
||||||
|
github.com/mmcloughlin/addchain v0.4.0 // indirect
|
||||||
|
github.com/nspcc-dev/dbft v0.0.0-20230515113611-25db6ba61d5c // indirect
|
||||||
|
github.com/nspcc-dev/go-ordered-json v0.0.0-20220111165707-25110be27d22 // indirect
|
||||||
|
github.com/nspcc-dev/neofs-crypto v0.4.0 // indirect
|
||||||
|
github.com/nspcc-dev/rfc6979 v0.2.0 // indirect
|
||||||
|
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
|
||||||
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
github.com/prometheus/client_golang v1.13.0 // indirect
|
||||||
|
github.com/prometheus/client_model v0.2.0 // indirect
|
||||||
|
github.com/prometheus/common v0.37.0 // indirect
|
||||||
|
github.com/prometheus/procfs v0.8.0 // indirect
|
||||||
|
github.com/rogpeppe/go-internal v1.11.0 // indirect
|
||||||
|
github.com/russross/blackfriday/v2 v2.0.1 // indirect
|
||||||
|
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
|
||||||
|
github.com/syndtr/goleveldb v1.0.1-0.20210305035536-64b5b1c73954 // indirect
|
||||||
|
github.com/twmb/murmur3 v1.1.5 // indirect
|
||||||
|
github.com/urfave/cli v1.22.5 // indirect
|
||||||
|
go.etcd.io/bbolt v1.3.7 // indirect
|
||||||
|
go.uber.org/multierr v1.10.0 // indirect
|
||||||
|
golang.org/x/crypto v0.14.0 // indirect
|
||||||
|
golang.org/x/mod v0.12.0 // indirect
|
||||||
|
golang.org/x/sync v0.3.0 // indirect
|
||||||
|
golang.org/x/sys v0.13.0 // indirect
|
||||||
|
golang.org/x/term v0.13.0 // indirect
|
||||||
|
golang.org/x/text v0.13.0 // indirect
|
||||||
|
golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846 // indirect
|
||||||
|
google.golang.org/protobuf v1.31.0 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
rsc.io/tmplfunc v0.0.3 // indirect
|
||||||
)
|
)
|
||||||
|
|
|
@ -32,15 +32,14 @@ in the network by invoking NewEpoch method.
|
||||||
|
|
||||||
# Contract storage scheme
|
# Contract storage scheme
|
||||||
|
|
||||||
| Key | Value | Description |
|
| Key | Value | Description |
|
||||||
|-----------------------------|------------|-----------------------------------|
|
|-----------------------------|------------|-----------------------------------|
|
||||||
| `snapshotCount` | int | snapshot count |
|
| `snapshotCount` | int | snapshot count |
|
||||||
| `snapshotEpoch` | int | snapshot epoch |
|
| `snapshotEpoch` | int | snapshot epoch |
|
||||||
| `snapshotBlock` | int | snapshot block |
|
| `snapshotBlock` | int | snapshot block |
|
||||||
| `snapshot_` + snapshotNum | ByteArray | serialized '[]Node' array |
|
| `snapshot_` + snapshotNum | ByteArray | serialized '[]Node' array |
|
||||||
| `snapshotCurrent` | int | current snapshot |
|
| `snapshotCurrent` | int | current snapshot |
|
||||||
| `balanceScriptHash` | Hash160 | balance contract hash |
|
| `balanceScriptHash` | Hash160 | balance contract hash |
|
||||||
| `containerScriptHash` | Hash160 | container contract hash |
|
| `containerScriptHash` | Hash160 | container contract hash |
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package netmap
|
package netmap
|
||||||
|
|
|
@ -43,8 +43,7 @@ type Node struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
notaryDisabledKey = "notary"
|
innerRingKey = "innerring"
|
||||||
innerRingKey = "innerring"
|
|
||||||
|
|
||||||
// DefaultSnapshotCount contains the number of previous snapshots stored by this contract.
|
// DefaultSnapshotCount contains the number of previous snapshots stored by this contract.
|
||||||
// Must be less than 255.
|
// Must be less than 255.
|
||||||
|
@ -67,19 +66,15 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// _deploy function sets up initial list of inner ring public keys.
|
// _deploy function sets up initial list of inner ring public keys.
|
||||||
func _deploy(data interface{}, isUpdate bool) {
|
func _deploy(data any, isUpdate bool) {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
common.RmAndCheckNotaryDisabledKey(data, notaryDisabledKey)
|
args := data.(struct {
|
||||||
|
addrBalance interop.Hash160
|
||||||
var args = data.(struct {
|
addrContainer interop.Hash160
|
||||||
//TODO(@acid-ant): #9 remove notaryDisabled in future version
|
keys []interop.PublicKey
|
||||||
notaryDisabled bool
|
config [][]byte
|
||||||
addrBalance interop.Hash160
|
version int
|
||||||
addrContainer interop.Hash160
|
|
||||||
keys []interop.PublicKey
|
|
||||||
config [][]byte
|
|
||||||
version int
|
|
||||||
})
|
})
|
||||||
|
|
||||||
ln := len(args.config)
|
ln := len(args.config)
|
||||||
|
@ -122,7 +117,7 @@ func _deploy(data interface{}, isUpdate bool) {
|
||||||
|
|
||||||
// Update method updates contract source code and manifest. It can be invoked
|
// Update method updates contract source code and manifest. It can be invoked
|
||||||
// only by committee.
|
// only by committee.
|
||||||
func Update(script []byte, manifest []byte, data interface{}) {
|
func Update(script []byte, manifest []byte, data any) {
|
||||||
if !common.HasUpdateAccess() {
|
if !common.HasUpdateAccess() {
|
||||||
panic("only committee can update contract")
|
panic("only committee can update contract")
|
||||||
}
|
}
|
||||||
|
@ -431,7 +426,7 @@ func SnapshotByEpoch(epoch int) []Node {
|
||||||
|
|
||||||
// Config returns configuration value of FrostFS configuration. If key does
|
// Config returns configuration value of FrostFS configuration. If key does
|
||||||
// not exists, returns nil.
|
// not exists, returns nil.
|
||||||
func Config(key []byte) interface{} {
|
func Config(key []byte) any {
|
||||||
ctx := storage.GetReadOnlyContext()
|
ctx := storage.GetReadOnlyContext()
|
||||||
return getConfig(ctx, key)
|
return getConfig(ctx, key)
|
||||||
}
|
}
|
||||||
|
@ -543,14 +538,14 @@ func getSnapshot(ctx storage.Context, key string) []Node {
|
||||||
return []Node{}
|
return []Node{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getConfig(ctx storage.Context, key interface{}) interface{} {
|
func getConfig(ctx storage.Context, key any) interface{} {
|
||||||
postfix := key.([]byte)
|
postfix := key.([]byte)
|
||||||
storageKey := append(configPrefix, postfix...)
|
storageKey := append(configPrefix, postfix...)
|
||||||
|
|
||||||
return storage.Get(ctx, storageKey)
|
return storage.Get(ctx, storageKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setConfig(ctx storage.Context, key, val interface{}) {
|
func setConfig(ctx storage.Context, key, val any) {
|
||||||
postfix := key.([]byte)
|
postfix := key.([]byte)
|
||||||
storageKey := append(configPrefix, postfix...)
|
storageKey := append(configPrefix, postfix...)
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ type RecordState struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update updates NameService contract.
|
// Update updates NameService contract.
|
||||||
func Update(nef []byte, manifest string, data interface{}) {
|
func Update(nef []byte, manifest string, data any) {
|
||||||
checkCommittee()
|
checkCommittee()
|
||||||
// Calculating keys and serializing requires calling
|
// Calculating keys and serializing requires calling
|
||||||
// std and crypto contracts. This can be helpful on update
|
// std and crypto contracts. This can be helpful on update
|
||||||
|
@ -87,9 +87,9 @@ func Update(nef []byte, manifest string, data interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// _deploy initializes defaults (total supply and registration price) on contract deploy.
|
// _deploy initializes defaults (total supply and registration price) on contract deploy.
|
||||||
func _deploy(data interface{}, isUpdate bool) {
|
func _deploy(data any, isUpdate bool) {
|
||||||
if isUpdate {
|
if isUpdate {
|
||||||
args := data.([]interface{})
|
args := data.([]any)
|
||||||
common.CheckVersion(args[len(args)-1].(int))
|
common.CheckVersion(args[len(args)-1].(int))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -128,10 +128,10 @@ func OwnerOf(tokenID []byte) interop.Hash160 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Properties returns a domain name and an expiration date of the specified domain.
|
// Properties returns a domain name and an expiration date of the specified domain.
|
||||||
func Properties(tokenID []byte) map[string]interface{} {
|
func Properties(tokenID []byte) map[string]any {
|
||||||
ctx := storage.GetReadOnlyContext()
|
ctx := storage.GetReadOnlyContext()
|
||||||
ns := getNameState(ctx, tokenID)
|
ns := getNameState(ctx, tokenID)
|
||||||
return map[string]interface{}{
|
return map[string]any{
|
||||||
"name": ns.Name,
|
"name": ns.Name,
|
||||||
"expiration": ns.Expiration,
|
"expiration": ns.Expiration,
|
||||||
}
|
}
|
||||||
|
@ -166,7 +166,7 @@ func TokensOf(owner interop.Hash160) iterator.Iterator {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transfer transfers the domain with the specified name to a new owner.
|
// Transfer transfers the domain with the specified name to a new owner.
|
||||||
func Transfer(to interop.Hash160, tokenID []byte, data interface{}) bool {
|
func Transfer(to interop.Hash160, tokenID []byte, data any) bool {
|
||||||
if !isValid(to) {
|
if !isValid(to) {
|
||||||
panic(`invalid receiver`)
|
panic(`invalid receiver`)
|
||||||
}
|
}
|
||||||
|
@ -458,13 +458,13 @@ func updateBalance(ctx storage.Context, tokenId []byte, acc interop.Hash160, dif
|
||||||
balanceKey := append([]byte{prefixBalance}, acc...)
|
balanceKey := append([]byte{prefixBalance}, acc...)
|
||||||
var balance int
|
var balance int
|
||||||
if b := storage.Get(ctx, balanceKey); b != nil {
|
if b := storage.Get(ctx, balanceKey); b != nil {
|
||||||
balance = b.(int)
|
balance = common.FromFixedWidth64(b.([]byte))
|
||||||
}
|
}
|
||||||
balance += diff
|
balance += diff
|
||||||
if balance == 0 {
|
if balance == 0 {
|
||||||
storage.Delete(ctx, balanceKey)
|
storage.Delete(ctx, balanceKey)
|
||||||
} else {
|
} else {
|
||||||
storage.Put(ctx, balanceKey, balance)
|
storage.Put(ctx, balanceKey, common.ToFixedWidth64(balance))
|
||||||
}
|
}
|
||||||
|
|
||||||
tokenKey := getTokenKey(tokenId)
|
tokenKey := getTokenKey(tokenId)
|
||||||
|
@ -478,7 +478,7 @@ func updateBalance(ctx storage.Context, tokenId []byte, acc interop.Hash160, dif
|
||||||
|
|
||||||
// postTransfer sends Transfer notification to the network and calls onNEP11Payment
|
// postTransfer sends Transfer notification to the network and calls onNEP11Payment
|
||||||
// method.
|
// method.
|
||||||
func postTransfer(from, to interop.Hash160, tokenID []byte, data interface{}) {
|
func postTransfer(from, to interop.Hash160, tokenID []byte, data any) {
|
||||||
runtime.Notify("Transfer", from, to, 1, tokenID)
|
runtime.Notify("Transfer", from, to, 1, tokenID)
|
||||||
if management.GetContract(to) != nil {
|
if management.GetContract(to) != nil {
|
||||||
contract.Call(to, "onNEP11Payment", contract.All, from, 1, tokenID, data)
|
contract.Call(to, "onNEP11Payment", contract.All, from, 1, tokenID, data)
|
||||||
|
@ -488,14 +488,14 @@ func postTransfer(from, to interop.Hash160, tokenID []byte, data interface{}) {
|
||||||
// getTotalSupply returns total supply from storage.
|
// getTotalSupply returns total supply from storage.
|
||||||
func getTotalSupply(ctx storage.Context) int {
|
func getTotalSupply(ctx storage.Context) int {
|
||||||
val := storage.Get(ctx, []byte{prefixTotalSupply})
|
val := storage.Get(ctx, []byte{prefixTotalSupply})
|
||||||
return val.(int)
|
return common.FromFixedWidth64(val.([]byte))
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateTotalSupply adds the specified diff to the total supply.
|
// updateTotalSupply adds the specified diff to the total supply.
|
||||||
func updateTotalSupply(ctx storage.Context, diff int) {
|
func updateTotalSupply(ctx storage.Context, diff int) {
|
||||||
tsKey := []byte{prefixTotalSupply}
|
tsKey := []byte{prefixTotalSupply}
|
||||||
ts := getTotalSupply(ctx)
|
ts := getTotalSupply(ctx)
|
||||||
storage.Put(ctx, tsKey, ts+diff)
|
storage.Put(ctx, tsKey, common.ToFixedWidth64(ts+diff))
|
||||||
}
|
}
|
||||||
|
|
||||||
// getTokenKey computes hash160 from the given tokenID.
|
// getTokenKey computes hash160 from the given tokenID.
|
||||||
|
|
6
policy/config.yml
Normal file
6
policy/config.yml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
name: "APE"
|
||||||
|
safemethods:
|
||||||
|
- "getAdmin"
|
||||||
|
- "listChains"
|
||||||
|
- "getChain"
|
||||||
|
- "listChainsByPrefix"
|
12
policy/doc.go
Normal file
12
policy/doc.go
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
# Contract storage scheme
|
||||||
|
|
||||||
|
| Key | Value | Description |
|
||||||
|
|------------------------------------------|--------|-----------------------------------|
|
||||||
|
| 'c' + uint16(len(container)) + container | []byte | Namespace chain |
|
||||||
|
| 'n' + uint16(len(namespace)) + namespace | []byte | Container chain |
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
package policy
|
147
policy/policy_contract.go
Normal file
147
policy/policy_contract.go
Normal file
|
@ -0,0 +1,147 @@
|
||||||
|
package policy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-contract/common"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/interop"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/interop/iterator"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Kind represents the object the chain is attached to.
|
||||||
|
// Currently only namespace and container are supported.
|
||||||
|
type Kind byte
|
||||||
|
|
||||||
|
const (
|
||||||
|
Namespace = 'n'
|
||||||
|
Container = 'c'
|
||||||
|
IAM = 'i'
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ownerKeyPrefix = 'o'
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// ErrNotAuthorized is returned when the none of the transaction signers
|
||||||
|
// belongs to the list of autorized keys.
|
||||||
|
ErrNotAuthorized = "none of the signers is authorized to change the contract"
|
||||||
|
)
|
||||||
|
|
||||||
|
// _deploy function sets up initial list of inner ring public keys.
|
||||||
|
func _deploy(data any, isUpdate bool) {
|
||||||
|
if isUpdate {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
args := data.(struct {
|
||||||
|
Admin interop.Hash160
|
||||||
|
})
|
||||||
|
ctx := storage.GetContext()
|
||||||
|
if args.Admin != nil {
|
||||||
|
if len(args.Admin) != 20 {
|
||||||
|
panic("invaliad admin hash length")
|
||||||
|
}
|
||||||
|
storage.Put(ctx, []byte{ownerKeyPrefix}, args.Admin)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkAuthorization(ctx storage.Context) {
|
||||||
|
admin := getAdmin(ctx)
|
||||||
|
if admin != nil && runtime.CheckWitness(admin) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if runtime.CheckWitness(common.AlphabetAddress()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
panic(ErrNotAuthorized)
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetAdmin(addr interop.Hash160) {
|
||||||
|
common.CheckAlphabetWitness()
|
||||||
|
|
||||||
|
ctx := storage.GetContext()
|
||||||
|
storage.Put(ctx, []byte{ownerKeyPrefix}, addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAdmin() interop.Hash160 {
|
||||||
|
ctx := storage.GetReadOnlyContext()
|
||||||
|
return getAdmin(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAdmin(ctx storage.Context) interop.Hash160 {
|
||||||
|
return storage.Get(ctx, []byte{ownerKeyPrefix}).(interop.Hash160)
|
||||||
|
}
|
||||||
|
|
||||||
|
func storageKey(prefix Kind, entityName string, name []byte) []byte {
|
||||||
|
ln := len(entityName)
|
||||||
|
key := append([]byte{byte(prefix)}, byte(ln&0xFF), byte(ln>>8))
|
||||||
|
key = append(key, entityName...)
|
||||||
|
return append(key, name...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddChain(entity Kind, entityName string, name []byte, chain []byte) {
|
||||||
|
ctx := storage.GetContext()
|
||||||
|
checkAuthorization(ctx)
|
||||||
|
|
||||||
|
key := storageKey(entity, entityName, name)
|
||||||
|
storage.Put(ctx, key, chain)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetChain(entity Kind, entityName string, name []byte) []byte {
|
||||||
|
ctx := storage.GetReadOnlyContext()
|
||||||
|
key := storageKey(entity, entityName, name)
|
||||||
|
data := storage.Get(ctx, key).([]byte)
|
||||||
|
if data == nil {
|
||||||
|
panic("not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
func RemoveChain(entity Kind, entityName string, name []byte) {
|
||||||
|
ctx := storage.GetContext()
|
||||||
|
checkAuthorization(ctx)
|
||||||
|
|
||||||
|
key := storageKey(entity, entityName, name)
|
||||||
|
storage.Delete(ctx, key)
|
||||||
|
}
|
||||||
|
|
||||||
|
func RemoveChainsByPrefix(entity Kind, entityName string, name []byte) {
|
||||||
|
ctx := storage.GetContext()
|
||||||
|
checkAuthorization(ctx)
|
||||||
|
|
||||||
|
key := storageKey(entity, entityName, name)
|
||||||
|
it := storage.Find(ctx, key, storage.KeysOnly)
|
||||||
|
for iterator.Next(it) {
|
||||||
|
storage.Delete(ctx, iterator.Value(it).([]byte))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListChains lists all chains for the namespace by prefix.
|
||||||
|
// container may be empty.
|
||||||
|
func ListChains(namespace, container string, name []byte) [][]byte {
|
||||||
|
result := ListChainsByPrefix(Namespace, namespace, name)
|
||||||
|
|
||||||
|
if container != "" {
|
||||||
|
result = append(result, ListChainsByPrefix(Container, container, name)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListChainsByPrefix list all chains for the provided kind and entity by prefix.
|
||||||
|
func ListChainsByPrefix(entity Kind, entityName string, prefix []byte) [][]byte {
|
||||||
|
ctx := storage.GetReadOnlyContext()
|
||||||
|
|
||||||
|
result := [][]byte{}
|
||||||
|
|
||||||
|
keyPrefix := storageKey(entity, entityName, prefix)
|
||||||
|
it := storage.Find(ctx, keyPrefix, storage.ValuesOnly)
|
||||||
|
for iterator.Next(it) {
|
||||||
|
result = append(result, iterator.Value(it).([]byte))
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
|
@ -21,9 +21,8 @@ Processing contract does not produce notifications to process.
|
||||||
|
|
||||||
# Contract storage scheme
|
# Contract storage scheme
|
||||||
|
|
||||||
| Key | Value | Description |
|
| Key | Value | Description |
|
||||||
|-----------------------------|------------|----------------------------------|
|
|-----------------------------|------------|----------------------------------|
|
||||||
| `frostfsScriptHash` | Hash160 | frostFS contract hash |
|
| `frostfsScriptHash` | Hash160 | frostFS contract hash |
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package processing
|
package processing
|
||||||
|
|
|
@ -19,16 +19,16 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// OnNEP17Payment is a callback for NEP-17 compatible native GAS contract.
|
// OnNEP17Payment is a callback for NEP-17 compatible native GAS contract.
|
||||||
func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
|
func OnNEP17Payment(from interop.Hash160, amount int, data any) {
|
||||||
caller := runtime.GetCallingScriptHash()
|
caller := runtime.GetCallingScriptHash()
|
||||||
if !common.BytesEqual(caller, []byte(gas.Hash)) {
|
if !common.BytesEqual(caller, []byte(gas.Hash)) {
|
||||||
common.AbortWithMessage("processing contract accepts GAS only")
|
common.AbortWithMessage("processing contract accepts GAS only")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func _deploy(data interface{}, isUpdate bool) {
|
func _deploy(data any, isUpdate bool) {
|
||||||
if isUpdate {
|
if isUpdate {
|
||||||
args := data.([]interface{})
|
args := data.([]any)
|
||||||
common.CheckVersion(args[len(args)-1].(int))
|
common.CheckVersion(args[len(args)-1].(int))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ func _deploy(data interface{}, isUpdate bool) {
|
||||||
|
|
||||||
// Update method updates contract source code and manifest. It can be invoked
|
// Update method updates contract source code and manifest. It can be invoked
|
||||||
// only by the sidechain committee.
|
// only by the sidechain committee.
|
||||||
func Update(script []byte, manifest []byte, data interface{}) {
|
func Update(script []byte, manifest []byte, data any) {
|
||||||
blockHeight := ledger.CurrentIndex()
|
blockHeight := ledger.CurrentIndex()
|
||||||
alphabetKeys := roles.GetDesignatedByRole(roles.NeoFSAlphabet, uint32(blockHeight+1))
|
alphabetKeys := roles.GetDesignatedByRole(roles.NeoFSAlphabet, uint32(blockHeight+1))
|
||||||
alphabetCommittee := common.Multiaddress(alphabetKeys, true)
|
alphabetCommittee := common.Multiaddress(alphabetKeys, true)
|
||||||
|
|
|
@ -21,6 +21,5 @@ Proxy contract does not produce notifications to process.
|
||||||
# Contract storage scheme
|
# Contract storage scheme
|
||||||
|
|
||||||
Proxy contract does not use storage
|
Proxy contract does not use storage
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package proxy
|
package proxy
|
||||||
|
|
|
@ -10,16 +10,16 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// OnNEP17Payment is a callback for NEP-17 compatible native GAS contract.
|
// OnNEP17Payment is a callback for NEP-17 compatible native GAS contract.
|
||||||
func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
|
func OnNEP17Payment(from interop.Hash160, amount int, data any) {
|
||||||
caller := runtime.GetCallingScriptHash()
|
caller := runtime.GetCallingScriptHash()
|
||||||
if !common.BytesEqual(caller, []byte(gas.Hash)) {
|
if !common.BytesEqual(caller, []byte(gas.Hash)) {
|
||||||
common.AbortWithMessage("proxy contract accepts GAS only")
|
common.AbortWithMessage("proxy contract accepts GAS only")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func _deploy(data interface{}, isUpdate bool) {
|
func _deploy(data any, isUpdate bool) {
|
||||||
if isUpdate {
|
if isUpdate {
|
||||||
args := data.([]interface{})
|
args := data.([]any)
|
||||||
common.CheckVersion(args[len(args)-1].(int))
|
common.CheckVersion(args[len(args)-1].(int))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ func _deploy(data interface{}, isUpdate bool) {
|
||||||
|
|
||||||
// Update method updates contract source code and manifest. It can be invoked
|
// Update method updates contract source code and manifest. It can be invoked
|
||||||
// only by committee.
|
// only by committee.
|
||||||
func Update(script []byte, manifest []byte, data interface{}) {
|
func Update(script []byte, manifest []byte, data any) {
|
||||||
if !common.HasUpdateAccess() {
|
if !common.HasUpdateAccess() {
|
||||||
panic("only committee can update contract")
|
panic("only committee can update contract")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
name: "Reputation"
|
|
||||||
safemethods: ["get", "getByID", "listByEpoch"]
|
|
||||||
permissions:
|
|
||||||
- methods: ["update"]
|
|
||||||
events:
|
|
||||||
- name: reputationPut
|
|
||||||
parameters:
|
|
||||||
- name: epoch
|
|
||||||
type: Integer
|
|
||||||
- name: peerID
|
|
||||||
type: ByteArray
|
|
||||||
- name: value
|
|
||||||
type: ByteArray
|
|
|
@ -1,25 +0,0 @@
|
||||||
/*
|
|
||||||
Reputation contract is a contract deployed in FrostFS sidechain.
|
|
||||||
|
|
||||||
Inner Ring nodes produce data audit for each container during each epoch. In the end,
|
|
||||||
nodes produce DataAuditResult structure that contains information about audit
|
|
||||||
progress. Reputation contract provides storage for such structures and simple
|
|
||||||
interface to iterate over available DataAuditResults on specified epoch.
|
|
||||||
|
|
||||||
During settlement process, Alphabet nodes fetch all DataAuditResult structures
|
|
||||||
from the epoch and execute balance transfers from data owners to Storage and
|
|
||||||
Inner Ring nodes if data audit succeeds.
|
|
||||||
|
|
||||||
# Contract notifications
|
|
||||||
|
|
||||||
Reputation contract does not produce notifications to process.
|
|
||||||
|
|
||||||
# Contract storage scheme
|
|
||||||
|
|
||||||
| Key | Value | Description |
|
|
||||||
|-----------------------------|------------|-----------------------------------|
|
|
||||||
| `c` + epoch + peerID | int | peer reputation count |
|
|
||||||
| `r` + count | ByteArray | serialized DataAuditResult struct |
|
|
||||||
|
|
||||||
*/
|
|
||||||
package reputation
|
|
|
@ -1,122 +0,0 @@
|
||||||
package reputation
|
|
||||||
|
|
||||||
import (
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-contract/common"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/convert"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/iterator"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/management"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
notaryDisabledKey = "notary"
|
|
||||||
reputationValuePrefix = 'r'
|
|
||||||
reputationCountPrefix = 'c'
|
|
||||||
)
|
|
||||||
|
|
||||||
func _deploy(data interface{}, isUpdate bool) {
|
|
||||||
common.RmAndCheckNotaryDisabledKey(data, notaryDisabledKey)
|
|
||||||
|
|
||||||
if isUpdate {
|
|
||||||
args := data.([]interface{})
|
|
||||||
common.CheckVersion(args[len(args)-1].(int))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
runtime.Log("reputation contract initialized")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update method updates contract source code and manifest. It can be invoked
|
|
||||||
// only by committee.
|
|
||||||
func Update(script []byte, manifest []byte, data interface{}) {
|
|
||||||
if !common.HasUpdateAccess() {
|
|
||||||
panic("only committee can update contract")
|
|
||||||
}
|
|
||||||
|
|
||||||
management.UpdateWithData(script, manifest, common.AppendVersion(data))
|
|
||||||
runtime.Log("reputation contract updated")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Put method saves DataAuditResult in contract storage. It can be invoked only by
|
|
||||||
// Inner Ring nodes. It does not require multisignature invocations.
|
|
||||||
//
|
|
||||||
// Epoch is the epoch number when DataAuditResult structure was generated.
|
|
||||||
// PeerID contains public keys of the Inner Ring node that has produced DataAuditResult.
|
|
||||||
// Value contains a stable marshaled structure of DataAuditResult.
|
|
||||||
func Put(epoch int, peerID []byte, value []byte) {
|
|
||||||
ctx := storage.GetContext()
|
|
||||||
|
|
||||||
multiaddr := common.AlphabetAddress()
|
|
||||||
if !runtime.CheckWitness(multiaddr) {
|
|
||||||
runtime.Notify("reputationPut", epoch, peerID, value)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
id := storageID(epoch, peerID)
|
|
||||||
key := getReputationKey(reputationCountPrefix, id)
|
|
||||||
rawCnt := storage.Get(ctx, key)
|
|
||||||
cnt := 0
|
|
||||||
if rawCnt != nil {
|
|
||||||
cnt = rawCnt.(int)
|
|
||||||
}
|
|
||||||
cnt++
|
|
||||||
storage.Put(ctx, key, cnt)
|
|
||||||
|
|
||||||
key[0] = reputationValuePrefix
|
|
||||||
key = append(key, convert.ToBytes(cnt)...)
|
|
||||||
storage.Put(ctx, key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get method returns a list of all stable marshaled DataAuditResult structures
|
|
||||||
// produced by the specified Inner Ring node during the specified epoch.
|
|
||||||
func Get(epoch int, peerID []byte) [][]byte {
|
|
||||||
id := storageID(epoch, peerID)
|
|
||||||
return GetByID(id)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetByID method returns a list of all stable marshaled DataAuditResult with
|
|
||||||
// the specified id. Use ListByEpoch method to obtain the id.
|
|
||||||
func GetByID(id []byte) [][]byte {
|
|
||||||
ctx := storage.GetReadOnlyContext()
|
|
||||||
|
|
||||||
var data [][]byte
|
|
||||||
|
|
||||||
it := storage.Find(ctx, getReputationKey(reputationValuePrefix, id), storage.ValuesOnly)
|
|
||||||
for iterator.Next(it) {
|
|
||||||
data = append(data, iterator.Value(it).([]byte))
|
|
||||||
}
|
|
||||||
return data
|
|
||||||
}
|
|
||||||
|
|
||||||
func getReputationKey(prefix byte, id []byte) []byte {
|
|
||||||
return append([]byte{prefix}, id...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListByEpoch returns a list of IDs that may be used to get reputation data
|
|
||||||
// with GetByID method.
|
|
||||||
func ListByEpoch(epoch int) [][]byte {
|
|
||||||
ctx := storage.GetReadOnlyContext()
|
|
||||||
key := getReputationKey(reputationCountPrefix, convert.ToBytes(epoch))
|
|
||||||
it := storage.Find(ctx, key, storage.KeysOnly)
|
|
||||||
|
|
||||||
var result [][]byte
|
|
||||||
|
|
||||||
for iterator.Next(it) {
|
|
||||||
key := iterator.Value(it).([]byte) // iterator MUST BE `storage.KeysOnly`
|
|
||||||
result = append(result, key[1:])
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
// Version returns the version of the contract.
|
|
||||||
func Version() int {
|
|
||||||
return common.Version
|
|
||||||
}
|
|
||||||
|
|
||||||
func storageID(epoch int, peerID []byte) []byte {
|
|
||||||
var buf interface{} = epoch
|
|
||||||
|
|
||||||
return append(buf.([]byte), peerID...)
|
|
||||||
}
|
|
138
rpcclient/alphabet/client.go
Normal file
138
rpcclient/alphabet/client.go
Normal file
|
@ -0,0 +1,138 @@
|
||||||
|
// Package alphabet contains RPC wrappers for Alphabet contract.
|
||||||
|
//
|
||||||
|
// Code generated by neo-go contract generate-rpcwrapper --manifest <file.json> --out <file.go> [--hash <hash>] [--config <config>]; DO NOT EDIT.
|
||||||
|
package alphabet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"math/big"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Invoker is used by ContractReader to call various safe methods.
|
||||||
|
type Invoker interface {
|
||||||
|
Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actor is used by Contract to call state-changing methods.
|
||||||
|
type Actor interface {
|
||||||
|
Invoker
|
||||||
|
|
||||||
|
MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error)
|
||||||
|
MakeRun(script []byte) (*transaction.Transaction, error)
|
||||||
|
MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error)
|
||||||
|
MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error)
|
||||||
|
SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error)
|
||||||
|
SendRun(script []byte) (util.Uint256, uint32, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContractReader implements safe contract methods.
|
||||||
|
type ContractReader struct {
|
||||||
|
invoker Invoker
|
||||||
|
hash util.Uint160
|
||||||
|
}
|
||||||
|
|
||||||
|
// Contract implements all contract methods.
|
||||||
|
type Contract struct {
|
||||||
|
ContractReader
|
||||||
|
actor Actor
|
||||||
|
hash util.Uint160
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewReader creates an instance of ContractReader using provided contract hash and the given Invoker.
|
||||||
|
func NewReader(invoker Invoker, hash util.Uint160) *ContractReader {
|
||||||
|
return &ContractReader{invoker, hash}
|
||||||
|
}
|
||||||
|
|
||||||
|
// New creates an instance of Contract using provided contract hash and the given Actor.
|
||||||
|
func New(actor Actor, hash util.Uint160) *Contract {
|
||||||
|
return &Contract{ContractReader{actor, hash}, actor, hash}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gas invokes `gas` method of contract.
|
||||||
|
func (c *ContractReader) Gas() (*big.Int, error) {
|
||||||
|
return unwrap.BigInt(c.invoker.Call(c.hash, "gas"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name invokes `name` method of contract.
|
||||||
|
func (c *ContractReader) Name() (string, error) {
|
||||||
|
return unwrap.UTF8String(c.invoker.Call(c.hash, "name"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Neo invokes `neo` method of contract.
|
||||||
|
func (c *ContractReader) Neo() (*big.Int, error) {
|
||||||
|
return unwrap.BigInt(c.invoker.Call(c.hash, "neo"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Version invokes `version` method of contract.
|
||||||
|
func (c *ContractReader) Version() (*big.Int, error) {
|
||||||
|
return unwrap.BigInt(c.invoker.Call(c.hash, "version"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Emit creates a transaction invoking `emit` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) Emit() (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "emit")
|
||||||
|
}
|
||||||
|
|
||||||
|
// EmitTransaction creates a transaction invoking `emit` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) EmitTransaction() (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "emit")
|
||||||
|
}
|
||||||
|
|
||||||
|
// EmitUnsigned creates a transaction invoking `emit` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) EmitUnsigned() (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "emit", nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update creates a transaction invoking `update` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) Update(script []byte, manifest []byte, data any) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "update", script, manifest, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTransaction creates a transaction invoking `update` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) UpdateTransaction(script []byte, manifest []byte, data any) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "update", script, manifest, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUnsigned creates a transaction invoking `update` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) UpdateUnsigned(script []byte, manifest []byte, data any) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "update", nil, script, manifest, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vote creates a transaction invoking `vote` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) Vote(epoch *big.Int, candidates []any) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "vote", epoch, candidates)
|
||||||
|
}
|
||||||
|
|
||||||
|
// VoteTransaction creates a transaction invoking `vote` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) VoteTransaction(epoch *big.Int, candidates []any) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "vote", epoch, candidates)
|
||||||
|
}
|
||||||
|
|
||||||
|
// VoteUnsigned creates a transaction invoking `vote` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) VoteUnsigned(epoch *big.Int, candidates []any) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "vote", nil, epoch, candidates)
|
||||||
|
}
|
549
rpcclient/balance/client.go
Normal file
549
rpcclient/balance/client.go
Normal file
|
@ -0,0 +1,549 @@
|
||||||
|
// Package balance contains RPC wrappers for Balance contract.
|
||||||
|
//
|
||||||
|
// Code generated by neo-go contract generate-rpcwrapper --manifest <file.json> --out <file.go> [--hash <hash>] [--config <config>]; DO NOT EDIT.
|
||||||
|
package balance
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/nep17"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
|
"math/big"
|
||||||
|
)
|
||||||
|
|
||||||
|
// LockEvent represents "Lock" event emitted by the contract.
|
||||||
|
type LockEvent struct {
|
||||||
|
TxID []byte
|
||||||
|
From util.Uint160
|
||||||
|
To util.Uint160
|
||||||
|
Amount *big.Int
|
||||||
|
Until *big.Int
|
||||||
|
}
|
||||||
|
|
||||||
|
// TransferXEvent represents "TransferX" event emitted by the contract.
|
||||||
|
type TransferXEvent struct {
|
||||||
|
From util.Uint160
|
||||||
|
To util.Uint160
|
||||||
|
Amount *big.Int
|
||||||
|
Details []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
// MintEvent represents "Mint" event emitted by the contract.
|
||||||
|
type MintEvent struct {
|
||||||
|
To util.Uint160
|
||||||
|
Amount *big.Int
|
||||||
|
}
|
||||||
|
|
||||||
|
// BurnEvent represents "Burn" event emitted by the contract.
|
||||||
|
type BurnEvent struct {
|
||||||
|
From util.Uint160
|
||||||
|
Amount *big.Int
|
||||||
|
}
|
||||||
|
|
||||||
|
// Invoker is used by ContractReader to call various safe methods.
|
||||||
|
type Invoker interface {
|
||||||
|
nep17.Invoker
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actor is used by Contract to call state-changing methods.
|
||||||
|
type Actor interface {
|
||||||
|
Invoker
|
||||||
|
|
||||||
|
nep17.Actor
|
||||||
|
|
||||||
|
MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error)
|
||||||
|
MakeRun(script []byte) (*transaction.Transaction, error)
|
||||||
|
MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error)
|
||||||
|
MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error)
|
||||||
|
SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error)
|
||||||
|
SendRun(script []byte) (util.Uint256, uint32, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContractReader implements safe contract methods.
|
||||||
|
type ContractReader struct {
|
||||||
|
nep17.TokenReader
|
||||||
|
invoker Invoker
|
||||||
|
hash util.Uint160
|
||||||
|
}
|
||||||
|
|
||||||
|
// Contract implements all contract methods.
|
||||||
|
type Contract struct {
|
||||||
|
ContractReader
|
||||||
|
nep17.TokenWriter
|
||||||
|
actor Actor
|
||||||
|
hash util.Uint160
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewReader creates an instance of ContractReader using provided contract hash and the given Invoker.
|
||||||
|
func NewReader(invoker Invoker, hash util.Uint160) *ContractReader {
|
||||||
|
return &ContractReader{*nep17.NewReader(invoker, hash), invoker, hash}
|
||||||
|
}
|
||||||
|
|
||||||
|
// New creates an instance of Contract using provided contract hash and the given Actor.
|
||||||
|
func New(actor Actor, hash util.Uint160) *Contract {
|
||||||
|
var nep17t = nep17.New(actor, hash)
|
||||||
|
return &Contract{ContractReader{nep17t.TokenReader, actor, hash}, nep17t.TokenWriter, actor, hash}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Version invokes `version` method of contract.
|
||||||
|
func (c *ContractReader) Version() (*big.Int, error) {
|
||||||
|
return unwrap.BigInt(c.invoker.Call(c.hash, "version"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Burn creates a transaction invoking `burn` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) Burn(from util.Uint160, amount *big.Int, txDetails []byte) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "burn", from, amount, txDetails)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BurnTransaction creates a transaction invoking `burn` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) BurnTransaction(from util.Uint160, amount *big.Int, txDetails []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "burn", from, amount, txDetails)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BurnUnsigned creates a transaction invoking `burn` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) BurnUnsigned(from util.Uint160, amount *big.Int, txDetails []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "burn", nil, from, amount, txDetails)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lock creates a transaction invoking `lock` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) Lock(txDetails []byte, from util.Uint160, to util.Uint160, amount *big.Int, until *big.Int) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "lock", txDetails, from, to, amount, until)
|
||||||
|
}
|
||||||
|
|
||||||
|
// LockTransaction creates a transaction invoking `lock` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) LockTransaction(txDetails []byte, from util.Uint160, to util.Uint160, amount *big.Int, until *big.Int) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "lock", txDetails, from, to, amount, until)
|
||||||
|
}
|
||||||
|
|
||||||
|
// LockUnsigned creates a transaction invoking `lock` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) LockUnsigned(txDetails []byte, from util.Uint160, to util.Uint160, amount *big.Int, until *big.Int) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "lock", nil, txDetails, from, to, amount, until)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mint creates a transaction invoking `mint` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) Mint(to util.Uint160, amount *big.Int, txDetails []byte) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "mint", to, amount, txDetails)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MintTransaction creates a transaction invoking `mint` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) MintTransaction(to util.Uint160, amount *big.Int, txDetails []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "mint", to, amount, txDetails)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MintUnsigned creates a transaction invoking `mint` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) MintUnsigned(to util.Uint160, amount *big.Int, txDetails []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "mint", nil, to, amount, txDetails)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewEpoch creates a transaction invoking `newEpoch` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) NewEpoch(epochNum *big.Int) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "newEpoch", epochNum)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewEpochTransaction creates a transaction invoking `newEpoch` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) NewEpochTransaction(epochNum *big.Int) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "newEpoch", epochNum)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewEpochUnsigned creates a transaction invoking `newEpoch` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) NewEpochUnsigned(epochNum *big.Int) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "newEpoch", nil, epochNum)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TransferX creates a transaction invoking `transferX` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) TransferX(from util.Uint160, to util.Uint160, amount *big.Int, details []byte) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "transferX", from, to, amount, details)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TransferXTransaction creates a transaction invoking `transferX` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) TransferXTransaction(from util.Uint160, to util.Uint160, amount *big.Int, details []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "transferX", from, to, amount, details)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TransferXUnsigned creates a transaction invoking `transferX` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) TransferXUnsigned(from util.Uint160, to util.Uint160, amount *big.Int, details []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "transferX", nil, from, to, amount, details)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update creates a transaction invoking `update` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) Update(script []byte, manifest []byte, data any) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "update", script, manifest, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTransaction creates a transaction invoking `update` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) UpdateTransaction(script []byte, manifest []byte, data any) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "update", script, manifest, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUnsigned creates a transaction invoking `update` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) UpdateUnsigned(script []byte, manifest []byte, data any) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "update", nil, script, manifest, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// LockEventsFromApplicationLog retrieves a set of all emitted events
|
||||||
|
// with "Lock" name from the provided [result.ApplicationLog].
|
||||||
|
func LockEventsFromApplicationLog(log *result.ApplicationLog) ([]*LockEvent, error) {
|
||||||
|
if log == nil {
|
||||||
|
return nil, errors.New("nil application log")
|
||||||
|
}
|
||||||
|
|
||||||
|
var res []*LockEvent
|
||||||
|
for i, ex := range log.Executions {
|
||||||
|
for j, e := range ex.Events {
|
||||||
|
if e.Name != "Lock" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
event := new(LockEvent)
|
||||||
|
err := event.FromStackItem(e.Item)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to deserialize LockEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
||||||
|
}
|
||||||
|
res = append(res, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromStackItem converts provided [stackitem.Array] to LockEvent or
|
||||||
|
// returns an error if it's not possible to do to so.
|
||||||
|
func (e *LockEvent) FromStackItem(item *stackitem.Array) error {
|
||||||
|
if item == nil {
|
||||||
|
return errors.New("nil item")
|
||||||
|
}
|
||||||
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("not an array")
|
||||||
|
}
|
||||||
|
if len(arr) != 5 {
|
||||||
|
return errors.New("wrong number of structure elements")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
index = -1
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
index++
|
||||||
|
e.TxID, err = arr[index].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field TxID: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.From, err = func(item stackitem.Item) (util.Uint160, error) {
|
||||||
|
b, err := item.TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, err
|
||||||
|
}
|
||||||
|
u, err := util.Uint160DecodeBytesBE(b)
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, err
|
||||||
|
}
|
||||||
|
return u, nil
|
||||||
|
}(arr[index])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field From: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.To, err = func(item stackitem.Item) (util.Uint160, error) {
|
||||||
|
b, err := item.TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, err
|
||||||
|
}
|
||||||
|
u, err := util.Uint160DecodeBytesBE(b)
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, err
|
||||||
|
}
|
||||||
|
return u, nil
|
||||||
|
}(arr[index])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field To: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.Amount, err = arr[index].TryInteger()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field Amount: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.Until, err = arr[index].TryInteger()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field Until: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// TransferXEventsFromApplicationLog retrieves a set of all emitted events
|
||||||
|
// with "TransferX" name from the provided [result.ApplicationLog].
|
||||||
|
func TransferXEventsFromApplicationLog(log *result.ApplicationLog) ([]*TransferXEvent, error) {
|
||||||
|
if log == nil {
|
||||||
|
return nil, errors.New("nil application log")
|
||||||
|
}
|
||||||
|
|
||||||
|
var res []*TransferXEvent
|
||||||
|
for i, ex := range log.Executions {
|
||||||
|
for j, e := range ex.Events {
|
||||||
|
if e.Name != "TransferX" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
event := new(TransferXEvent)
|
||||||
|
err := event.FromStackItem(e.Item)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to deserialize TransferXEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
||||||
|
}
|
||||||
|
res = append(res, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromStackItem converts provided [stackitem.Array] to TransferXEvent or
|
||||||
|
// returns an error if it's not possible to do to so.
|
||||||
|
func (e *TransferXEvent) FromStackItem(item *stackitem.Array) error {
|
||||||
|
if item == nil {
|
||||||
|
return errors.New("nil item")
|
||||||
|
}
|
||||||
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("not an array")
|
||||||
|
}
|
||||||
|
if len(arr) != 4 {
|
||||||
|
return errors.New("wrong number of structure elements")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
index = -1
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
index++
|
||||||
|
e.From, err = func(item stackitem.Item) (util.Uint160, error) {
|
||||||
|
b, err := item.TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, err
|
||||||
|
}
|
||||||
|
u, err := util.Uint160DecodeBytesBE(b)
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, err
|
||||||
|
}
|
||||||
|
return u, nil
|
||||||
|
}(arr[index])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field From: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.To, err = func(item stackitem.Item) (util.Uint160, error) {
|
||||||
|
b, err := item.TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, err
|
||||||
|
}
|
||||||
|
u, err := util.Uint160DecodeBytesBE(b)
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, err
|
||||||
|
}
|
||||||
|
return u, nil
|
||||||
|
}(arr[index])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field To: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.Amount, err = arr[index].TryInteger()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field Amount: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.Details, err = arr[index].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field Details: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MintEventsFromApplicationLog retrieves a set of all emitted events
|
||||||
|
// with "Mint" name from the provided [result.ApplicationLog].
|
||||||
|
func MintEventsFromApplicationLog(log *result.ApplicationLog) ([]*MintEvent, error) {
|
||||||
|
if log == nil {
|
||||||
|
return nil, errors.New("nil application log")
|
||||||
|
}
|
||||||
|
|
||||||
|
var res []*MintEvent
|
||||||
|
for i, ex := range log.Executions {
|
||||||
|
for j, e := range ex.Events {
|
||||||
|
if e.Name != "Mint" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
event := new(MintEvent)
|
||||||
|
err := event.FromStackItem(e.Item)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to deserialize MintEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
||||||
|
}
|
||||||
|
res = append(res, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromStackItem converts provided [stackitem.Array] to MintEvent or
|
||||||
|
// returns an error if it's not possible to do to so.
|
||||||
|
func (e *MintEvent) FromStackItem(item *stackitem.Array) error {
|
||||||
|
if item == nil {
|
||||||
|
return errors.New("nil item")
|
||||||
|
}
|
||||||
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("not an array")
|
||||||
|
}
|
||||||
|
if len(arr) != 2 {
|
||||||
|
return errors.New("wrong number of structure elements")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
index = -1
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
index++
|
||||||
|
e.To, err = func(item stackitem.Item) (util.Uint160, error) {
|
||||||
|
b, err := item.TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, err
|
||||||
|
}
|
||||||
|
u, err := util.Uint160DecodeBytesBE(b)
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, err
|
||||||
|
}
|
||||||
|
return u, nil
|
||||||
|
}(arr[index])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field To: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.Amount, err = arr[index].TryInteger()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field Amount: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BurnEventsFromApplicationLog retrieves a set of all emitted events
|
||||||
|
// with "Burn" name from the provided [result.ApplicationLog].
|
||||||
|
func BurnEventsFromApplicationLog(log *result.ApplicationLog) ([]*BurnEvent, error) {
|
||||||
|
if log == nil {
|
||||||
|
return nil, errors.New("nil application log")
|
||||||
|
}
|
||||||
|
|
||||||
|
var res []*BurnEvent
|
||||||
|
for i, ex := range log.Executions {
|
||||||
|
for j, e := range ex.Events {
|
||||||
|
if e.Name != "Burn" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
event := new(BurnEvent)
|
||||||
|
err := event.FromStackItem(e.Item)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to deserialize BurnEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
||||||
|
}
|
||||||
|
res = append(res, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromStackItem converts provided [stackitem.Array] to BurnEvent or
|
||||||
|
// returns an error if it's not possible to do to so.
|
||||||
|
func (e *BurnEvent) FromStackItem(item *stackitem.Array) error {
|
||||||
|
if item == nil {
|
||||||
|
return errors.New("nil item")
|
||||||
|
}
|
||||||
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("not an array")
|
||||||
|
}
|
||||||
|
if len(arr) != 2 {
|
||||||
|
return errors.New("wrong number of structure elements")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
index = -1
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
index++
|
||||||
|
e.From, err = func(item stackitem.Item) (util.Uint160, error) {
|
||||||
|
b, err := item.TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, err
|
||||||
|
}
|
||||||
|
u, err := util.Uint160DecodeBytesBE(b)
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, err
|
||||||
|
}
|
||||||
|
return u, nil
|
||||||
|
}(arr[index])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field From: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.Amount, err = arr[index].TryInteger()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field Amount: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
661
rpcclient/container/client.go
Normal file
661
rpcclient/container/client.go
Normal file
|
@ -0,0 +1,661 @@
|
||||||
|
// Package container contains RPC wrappers for Container contract.
|
||||||
|
//
|
||||||
|
// Code generated by neo-go contract generate-rpcwrapper --manifest <file.json> --out <file.go> [--hash <hash>] [--config <config>]; DO NOT EDIT.
|
||||||
|
package container
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/elliptic"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
|
"math/big"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PutSuccessEvent represents "PutSuccess" event emitted by the contract.
|
||||||
|
type PutSuccessEvent struct {
|
||||||
|
ContainerID util.Uint256
|
||||||
|
PublicKey *keys.PublicKey
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteSuccessEvent represents "DeleteSuccess" event emitted by the contract.
|
||||||
|
type DeleteSuccessEvent struct {
|
||||||
|
ContainerID []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetEACLSuccessEvent represents "SetEACLSuccess" event emitted by the contract.
|
||||||
|
type SetEACLSuccessEvent struct {
|
||||||
|
ContainerID []byte
|
||||||
|
PublicKey *keys.PublicKey
|
||||||
|
}
|
||||||
|
|
||||||
|
// StartEstimationEvent represents "StartEstimation" event emitted by the contract.
|
||||||
|
type StartEstimationEvent struct {
|
||||||
|
Epoch *big.Int
|
||||||
|
}
|
||||||
|
|
||||||
|
// StopEstimationEvent represents "StopEstimation" event emitted by the contract.
|
||||||
|
type StopEstimationEvent struct {
|
||||||
|
Epoch *big.Int
|
||||||
|
}
|
||||||
|
|
||||||
|
// Invoker is used by ContractReader to call various safe methods.
|
||||||
|
type Invoker interface {
|
||||||
|
Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error)
|
||||||
|
CallAndExpandIterator(contract util.Uint160, method string, maxItems int, params ...any) (*result.Invoke, error)
|
||||||
|
TerminateSession(sessionID uuid.UUID) error
|
||||||
|
TraverseIterator(sessionID uuid.UUID, iterator *result.Iterator, num int) ([]stackitem.Item, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actor is used by Contract to call state-changing methods.
|
||||||
|
type Actor interface {
|
||||||
|
Invoker
|
||||||
|
|
||||||
|
MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error)
|
||||||
|
MakeRun(script []byte) (*transaction.Transaction, error)
|
||||||
|
MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error)
|
||||||
|
MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error)
|
||||||
|
SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error)
|
||||||
|
SendRun(script []byte) (util.Uint256, uint32, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContractReader implements safe contract methods.
|
||||||
|
type ContractReader struct {
|
||||||
|
invoker Invoker
|
||||||
|
hash util.Uint160
|
||||||
|
}
|
||||||
|
|
||||||
|
// Contract implements all contract methods.
|
||||||
|
type Contract struct {
|
||||||
|
ContractReader
|
||||||
|
actor Actor
|
||||||
|
hash util.Uint160
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewReader creates an instance of ContractReader using provided contract hash and the given Invoker.
|
||||||
|
func NewReader(invoker Invoker, hash util.Uint160) *ContractReader {
|
||||||
|
return &ContractReader{invoker, hash}
|
||||||
|
}
|
||||||
|
|
||||||
|
// New creates an instance of Contract using provided contract hash and the given Actor.
|
||||||
|
func New(actor Actor, hash util.Uint160) *Contract {
|
||||||
|
return &Contract{ContractReader{actor, hash}, actor, hash}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContainersOf invokes `containersOf` method of contract.
|
||||||
|
func (c *ContractReader) ContainersOf(owner []byte) (uuid.UUID, result.Iterator, error) {
|
||||||
|
return unwrap.SessionIterator(c.invoker.Call(c.hash, "containersOf", owner))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContainersOfExpanded is similar to ContainersOf (uses the same contract
|
||||||
|
// method), but can be useful if the server used doesn't support sessions and
|
||||||
|
// doesn't expand iterators. It creates a script that will get the specified
|
||||||
|
// number of result items from the iterator right in the VM and return them to
|
||||||
|
// you. It's only limited by VM stack and GAS available for RPC invocations.
|
||||||
|
func (c *ContractReader) ContainersOfExpanded(owner []byte, _numOfIteratorItems int) ([]stackitem.Item, error) {
|
||||||
|
return unwrap.Array(c.invoker.CallAndExpandIterator(c.hash, "containersOf", _numOfIteratorItems, owner))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count invokes `count` method of contract.
|
||||||
|
func (c *ContractReader) Count() (*big.Int, error) {
|
||||||
|
return unwrap.BigInt(c.invoker.Call(c.hash, "count"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeletionInfo invokes `deletionInfo` method of contract.
|
||||||
|
func (c *ContractReader) DeletionInfo(containerID []byte) ([]stackitem.Item, error) {
|
||||||
|
return unwrap.Array(c.invoker.Call(c.hash, "deletionInfo", containerID))
|
||||||
|
}
|
||||||
|
|
||||||
|
// EACL invokes `eACL` method of contract.
|
||||||
|
func (c *ContractReader) EACL(containerID []byte) ([]stackitem.Item, error) {
|
||||||
|
return unwrap.Array(c.invoker.Call(c.hash, "eACL", containerID))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get invokes `get` method of contract.
|
||||||
|
func (c *ContractReader) Get(containerID []byte) ([]stackitem.Item, error) {
|
||||||
|
return unwrap.Array(c.invoker.Call(c.hash, "get", containerID))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetContainerSize invokes `getContainerSize` method of contract.
|
||||||
|
func (c *ContractReader) GetContainerSize(id []byte) ([]stackitem.Item, error) {
|
||||||
|
return unwrap.Array(c.invoker.Call(c.hash, "getContainerSize", id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IterateContainerSizes invokes `iterateContainerSizes` method of contract.
|
||||||
|
func (c *ContractReader) IterateContainerSizes(epoch *big.Int) (uuid.UUID, result.Iterator, error) {
|
||||||
|
return unwrap.SessionIterator(c.invoker.Call(c.hash, "iterateContainerSizes", epoch))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IterateContainerSizesExpanded is similar to IterateContainerSizes (uses the same contract
|
||||||
|
// method), but can be useful if the server used doesn't support sessions and
|
||||||
|
// doesn't expand iterators. It creates a script that will get the specified
|
||||||
|
// number of result items from the iterator right in the VM and return them to
|
||||||
|
// you. It's only limited by VM stack and GAS available for RPC invocations.
|
||||||
|
func (c *ContractReader) IterateContainerSizesExpanded(epoch *big.Int, _numOfIteratorItems int) ([]stackitem.Item, error) {
|
||||||
|
return unwrap.Array(c.invoker.CallAndExpandIterator(c.hash, "iterateContainerSizes", _numOfIteratorItems, epoch))
|
||||||
|
}
|
||||||
|
|
||||||
|
// List invokes `list` method of contract.
|
||||||
|
func (c *ContractReader) List(owner []byte) ([]stackitem.Item, error) {
|
||||||
|
return unwrap.Array(c.invoker.Call(c.hash, "list", owner))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListContainerSizes invokes `listContainerSizes` method of contract.
|
||||||
|
func (c *ContractReader) ListContainerSizes(epoch *big.Int) ([]stackitem.Item, error) {
|
||||||
|
return unwrap.Array(c.invoker.Call(c.hash, "listContainerSizes", epoch))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Owner invokes `owner` method of contract.
|
||||||
|
func (c *ContractReader) Owner(containerID []byte) ([]byte, error) {
|
||||||
|
return unwrap.Bytes(c.invoker.Call(c.hash, "owner", containerID))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Version invokes `version` method of contract.
|
||||||
|
func (c *ContractReader) Version() (*big.Int, error) {
|
||||||
|
return unwrap.BigInt(c.invoker.Call(c.hash, "version"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete creates a transaction invoking `delete` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) Delete(containerID []byte, signature []byte, publicKey *keys.PublicKey, token []byte) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "delete", containerID, signature, publicKey, token)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteTransaction creates a transaction invoking `delete` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) DeleteTransaction(containerID []byte, signature []byte, publicKey *keys.PublicKey, token []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "delete", containerID, signature, publicKey, token)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteUnsigned creates a transaction invoking `delete` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) DeleteUnsigned(containerID []byte, signature []byte, publicKey *keys.PublicKey, token []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "delete", nil, containerID, signature, publicKey, token)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewEpoch creates a transaction invoking `newEpoch` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) NewEpoch(epochNum *big.Int) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "newEpoch", epochNum)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewEpochTransaction creates a transaction invoking `newEpoch` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) NewEpochTransaction(epochNum *big.Int) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "newEpoch", epochNum)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewEpochUnsigned creates a transaction invoking `newEpoch` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) NewEpochUnsigned(epochNum *big.Int) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "newEpoch", nil, epochNum)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Put creates a transaction invoking `put` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) Put(container []byte, signature []byte, publicKey *keys.PublicKey, token []byte) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "put", container, signature, publicKey, token)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutTransaction creates a transaction invoking `put` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) PutTransaction(container []byte, signature []byte, publicKey *keys.PublicKey, token []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "put", container, signature, publicKey, token)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutUnsigned creates a transaction invoking `put` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) PutUnsigned(container []byte, signature []byte, publicKey *keys.PublicKey, token []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "put", nil, container, signature, publicKey, token)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutContainerSize creates a transaction invoking `putContainerSize` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) PutContainerSize(epoch *big.Int, cid []byte, usedSize *big.Int, pubKey *keys.PublicKey) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "putContainerSize", epoch, cid, usedSize, pubKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutContainerSizeTransaction creates a transaction invoking `putContainerSize` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) PutContainerSizeTransaction(epoch *big.Int, cid []byte, usedSize *big.Int, pubKey *keys.PublicKey) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "putContainerSize", epoch, cid, usedSize, pubKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutContainerSizeUnsigned creates a transaction invoking `putContainerSize` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) PutContainerSizeUnsigned(epoch *big.Int, cid []byte, usedSize *big.Int, pubKey *keys.PublicKey) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "putContainerSize", nil, epoch, cid, usedSize, pubKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutNamed creates a transaction invoking `putNamed` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) PutNamed(container []byte, signature []byte, publicKey *keys.PublicKey, token []byte, name string, zone string) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "putNamed", container, signature, publicKey, token, name, zone)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutNamedTransaction creates a transaction invoking `putNamed` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) PutNamedTransaction(container []byte, signature []byte, publicKey *keys.PublicKey, token []byte, name string, zone string) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "putNamed", container, signature, publicKey, token, name, zone)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutNamedUnsigned creates a transaction invoking `putNamed` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) PutNamedUnsigned(container []byte, signature []byte, publicKey *keys.PublicKey, token []byte, name string, zone string) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "putNamed", nil, container, signature, publicKey, token, name, zone)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetEACL creates a transaction invoking `setEACL` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) SetEACL(eACL []byte, signature []byte, publicKey *keys.PublicKey, token []byte) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "setEACL", eACL, signature, publicKey, token)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetEACLTransaction creates a transaction invoking `setEACL` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) SetEACLTransaction(eACL []byte, signature []byte, publicKey *keys.PublicKey, token []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "setEACL", eACL, signature, publicKey, token)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetEACLUnsigned creates a transaction invoking `setEACL` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) SetEACLUnsigned(eACL []byte, signature []byte, publicKey *keys.PublicKey, token []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "setEACL", nil, eACL, signature, publicKey, token)
|
||||||
|
}
|
||||||
|
|
||||||
|
// StartContainerEstimation creates a transaction invoking `startContainerEstimation` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) StartContainerEstimation(epoch *big.Int) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "startContainerEstimation", epoch)
|
||||||
|
}
|
||||||
|
|
||||||
|
// StartContainerEstimationTransaction creates a transaction invoking `startContainerEstimation` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) StartContainerEstimationTransaction(epoch *big.Int) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "startContainerEstimation", epoch)
|
||||||
|
}
|
||||||
|
|
||||||
|
// StartContainerEstimationUnsigned creates a transaction invoking `startContainerEstimation` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) StartContainerEstimationUnsigned(epoch *big.Int) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "startContainerEstimation", nil, epoch)
|
||||||
|
}
|
||||||
|
|
||||||
|
// StopContainerEstimation creates a transaction invoking `stopContainerEstimation` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) StopContainerEstimation(epoch *big.Int) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "stopContainerEstimation", epoch)
|
||||||
|
}
|
||||||
|
|
||||||
|
// StopContainerEstimationTransaction creates a transaction invoking `stopContainerEstimation` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) StopContainerEstimationTransaction(epoch *big.Int) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "stopContainerEstimation", epoch)
|
||||||
|
}
|
||||||
|
|
||||||
|
// StopContainerEstimationUnsigned creates a transaction invoking `stopContainerEstimation` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) StopContainerEstimationUnsigned(epoch *big.Int) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "stopContainerEstimation", nil, epoch)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update creates a transaction invoking `update` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) Update(script []byte, manifest []byte, data any) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "update", script, manifest, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTransaction creates a transaction invoking `update` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) UpdateTransaction(script []byte, manifest []byte, data any) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "update", script, manifest, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUnsigned creates a transaction invoking `update` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) UpdateUnsigned(script []byte, manifest []byte, data any) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "update", nil, script, manifest, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutSuccessEventsFromApplicationLog retrieves a set of all emitted events
|
||||||
|
// with "PutSuccess" name from the provided [result.ApplicationLog].
|
||||||
|
func PutSuccessEventsFromApplicationLog(log *result.ApplicationLog) ([]*PutSuccessEvent, error) {
|
||||||
|
if log == nil {
|
||||||
|
return nil, errors.New("nil application log")
|
||||||
|
}
|
||||||
|
|
||||||
|
var res []*PutSuccessEvent
|
||||||
|
for i, ex := range log.Executions {
|
||||||
|
for j, e := range ex.Events {
|
||||||
|
if e.Name != "PutSuccess" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
event := new(PutSuccessEvent)
|
||||||
|
err := event.FromStackItem(e.Item)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to deserialize PutSuccessEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
||||||
|
}
|
||||||
|
res = append(res, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromStackItem converts provided [stackitem.Array] to PutSuccessEvent or
|
||||||
|
// returns an error if it's not possible to do to so.
|
||||||
|
func (e *PutSuccessEvent) FromStackItem(item *stackitem.Array) error {
|
||||||
|
if item == nil {
|
||||||
|
return errors.New("nil item")
|
||||||
|
}
|
||||||
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("not an array")
|
||||||
|
}
|
||||||
|
if len(arr) != 2 {
|
||||||
|
return errors.New("wrong number of structure elements")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
index = -1
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
index++
|
||||||
|
e.ContainerID, err = func(item stackitem.Item) (util.Uint256, error) {
|
||||||
|
b, err := item.TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint256{}, err
|
||||||
|
}
|
||||||
|
u, err := util.Uint256DecodeBytesBE(b)
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint256{}, err
|
||||||
|
}
|
||||||
|
return u, nil
|
||||||
|
}(arr[index])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field ContainerID: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.PublicKey, err = func(item stackitem.Item) (*keys.PublicKey, error) {
|
||||||
|
b, err := item.TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
k, err := keys.NewPublicKeyFromBytes(b, elliptic.P256())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return k, nil
|
||||||
|
}(arr[index])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field PublicKey: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteSuccessEventsFromApplicationLog retrieves a set of all emitted events
|
||||||
|
// with "DeleteSuccess" name from the provided [result.ApplicationLog].
|
||||||
|
func DeleteSuccessEventsFromApplicationLog(log *result.ApplicationLog) ([]*DeleteSuccessEvent, error) {
|
||||||
|
if log == nil {
|
||||||
|
return nil, errors.New("nil application log")
|
||||||
|
}
|
||||||
|
|
||||||
|
var res []*DeleteSuccessEvent
|
||||||
|
for i, ex := range log.Executions {
|
||||||
|
for j, e := range ex.Events {
|
||||||
|
if e.Name != "DeleteSuccess" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
event := new(DeleteSuccessEvent)
|
||||||
|
err := event.FromStackItem(e.Item)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to deserialize DeleteSuccessEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
||||||
|
}
|
||||||
|
res = append(res, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromStackItem converts provided [stackitem.Array] to DeleteSuccessEvent or
|
||||||
|
// returns an error if it's not possible to do to so.
|
||||||
|
func (e *DeleteSuccessEvent) FromStackItem(item *stackitem.Array) error {
|
||||||
|
if item == nil {
|
||||||
|
return errors.New("nil item")
|
||||||
|
}
|
||||||
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("not an array")
|
||||||
|
}
|
||||||
|
if len(arr) != 1 {
|
||||||
|
return errors.New("wrong number of structure elements")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
index = -1
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
index++
|
||||||
|
e.ContainerID, err = arr[index].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field ContainerID: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetEACLSuccessEventsFromApplicationLog retrieves a set of all emitted events
|
||||||
|
// with "SetEACLSuccess" name from the provided [result.ApplicationLog].
|
||||||
|
func SetEACLSuccessEventsFromApplicationLog(log *result.ApplicationLog) ([]*SetEACLSuccessEvent, error) {
|
||||||
|
if log == nil {
|
||||||
|
return nil, errors.New("nil application log")
|
||||||
|
}
|
||||||
|
|
||||||
|
var res []*SetEACLSuccessEvent
|
||||||
|
for i, ex := range log.Executions {
|
||||||
|
for j, e := range ex.Events {
|
||||||
|
if e.Name != "SetEACLSuccess" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
event := new(SetEACLSuccessEvent)
|
||||||
|
err := event.FromStackItem(e.Item)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to deserialize SetEACLSuccessEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
||||||
|
}
|
||||||
|
res = append(res, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromStackItem converts provided [stackitem.Array] to SetEACLSuccessEvent or
|
||||||
|
// returns an error if it's not possible to do to so.
|
||||||
|
func (e *SetEACLSuccessEvent) FromStackItem(item *stackitem.Array) error {
|
||||||
|
if item == nil {
|
||||||
|
return errors.New("nil item")
|
||||||
|
}
|
||||||
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("not an array")
|
||||||
|
}
|
||||||
|
if len(arr) != 2 {
|
||||||
|
return errors.New("wrong number of structure elements")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
index = -1
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
index++
|
||||||
|
e.ContainerID, err = arr[index].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field ContainerID: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.PublicKey, err = func(item stackitem.Item) (*keys.PublicKey, error) {
|
||||||
|
b, err := item.TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
k, err := keys.NewPublicKeyFromBytes(b, elliptic.P256())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return k, nil
|
||||||
|
}(arr[index])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field PublicKey: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// StartEstimationEventsFromApplicationLog retrieves a set of all emitted events
|
||||||
|
// with "StartEstimation" name from the provided [result.ApplicationLog].
|
||||||
|
func StartEstimationEventsFromApplicationLog(log *result.ApplicationLog) ([]*StartEstimationEvent, error) {
|
||||||
|
if log == nil {
|
||||||
|
return nil, errors.New("nil application log")
|
||||||
|
}
|
||||||
|
|
||||||
|
var res []*StartEstimationEvent
|
||||||
|
for i, ex := range log.Executions {
|
||||||
|
for j, e := range ex.Events {
|
||||||
|
if e.Name != "StartEstimation" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
event := new(StartEstimationEvent)
|
||||||
|
err := event.FromStackItem(e.Item)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to deserialize StartEstimationEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
||||||
|
}
|
||||||
|
res = append(res, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromStackItem converts provided [stackitem.Array] to StartEstimationEvent or
|
||||||
|
// returns an error if it's not possible to do to so.
|
||||||
|
func (e *StartEstimationEvent) FromStackItem(item *stackitem.Array) error {
|
||||||
|
if item == nil {
|
||||||
|
return errors.New("nil item")
|
||||||
|
}
|
||||||
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("not an array")
|
||||||
|
}
|
||||||
|
if len(arr) != 1 {
|
||||||
|
return errors.New("wrong number of structure elements")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
index = -1
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
index++
|
||||||
|
e.Epoch, err = arr[index].TryInteger()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field Epoch: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// StopEstimationEventsFromApplicationLog retrieves a set of all emitted events
|
||||||
|
// with "StopEstimation" name from the provided [result.ApplicationLog].
|
||||||
|
func StopEstimationEventsFromApplicationLog(log *result.ApplicationLog) ([]*StopEstimationEvent, error) {
|
||||||
|
if log == nil {
|
||||||
|
return nil, errors.New("nil application log")
|
||||||
|
}
|
||||||
|
|
||||||
|
var res []*StopEstimationEvent
|
||||||
|
for i, ex := range log.Executions {
|
||||||
|
for j, e := range ex.Events {
|
||||||
|
if e.Name != "StopEstimation" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
event := new(StopEstimationEvent)
|
||||||
|
err := event.FromStackItem(e.Item)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to deserialize StopEstimationEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
||||||
|
}
|
||||||
|
res = append(res, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromStackItem converts provided [stackitem.Array] to StopEstimationEvent or
|
||||||
|
// returns an error if it's not possible to do to so.
|
||||||
|
func (e *StopEstimationEvent) FromStackItem(item *stackitem.Array) error {
|
||||||
|
if item == nil {
|
||||||
|
return errors.New("nil item")
|
||||||
|
}
|
||||||
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("not an array")
|
||||||
|
}
|
||||||
|
if len(arr) != 1 {
|
||||||
|
return errors.New("wrong number of structure elements")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
index = -1
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
index++
|
||||||
|
e.Epoch, err = arr[index].TryInteger()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field Epoch: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
851
rpcclient/frostfs/client.go
Normal file
851
rpcclient/frostfs/client.go
Normal file
|
@ -0,0 +1,851 @@
|
||||||
|
// Package frostfs contains RPC wrappers for FrostFS contract.
|
||||||
|
//
|
||||||
|
// Code generated by neo-go contract generate-rpcwrapper --manifest <file.json> --out <file.go> [--hash <hash>] [--config <config>]; DO NOT EDIT.
|
||||||
|
package frostfs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
|
"math/big"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DepositEvent represents "Deposit" event emitted by the contract.
|
||||||
|
type DepositEvent struct {
|
||||||
|
From util.Uint160
|
||||||
|
Amount *big.Int
|
||||||
|
Receiver util.Uint160
|
||||||
|
TxHash util.Uint256
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithdrawEvent represents "Withdraw" event emitted by the contract.
|
||||||
|
type WithdrawEvent struct {
|
||||||
|
User util.Uint160
|
||||||
|
Amount *big.Int
|
||||||
|
TxHash util.Uint256
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChequeEvent represents "Cheque" event emitted by the contract.
|
||||||
|
type ChequeEvent struct {
|
||||||
|
Id []byte
|
||||||
|
User util.Uint160
|
||||||
|
Amount *big.Int
|
||||||
|
LockAccount []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
// BindEvent represents "Bind" event emitted by the contract.
|
||||||
|
type BindEvent struct {
|
||||||
|
User []byte
|
||||||
|
Keys []any
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnbindEvent represents "Unbind" event emitted by the contract.
|
||||||
|
type UnbindEvent struct {
|
||||||
|
User []byte
|
||||||
|
Keys []any
|
||||||
|
}
|
||||||
|
|
||||||
|
// AlphabetUpdateEvent represents "AlphabetUpdate" event emitted by the contract.
|
||||||
|
type AlphabetUpdateEvent struct {
|
||||||
|
Id []byte
|
||||||
|
Alphabet []any
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetConfigEvent represents "SetConfig" event emitted by the contract.
|
||||||
|
type SetConfigEvent struct {
|
||||||
|
Id []byte
|
||||||
|
Key []byte
|
||||||
|
Value []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
// Invoker is used by ContractReader to call various safe methods.
|
||||||
|
type Invoker interface {
|
||||||
|
Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actor is used by Contract to call state-changing methods.
|
||||||
|
type Actor interface {
|
||||||
|
Invoker
|
||||||
|
|
||||||
|
MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error)
|
||||||
|
MakeRun(script []byte) (*transaction.Transaction, error)
|
||||||
|
MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error)
|
||||||
|
MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error)
|
||||||
|
SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error)
|
||||||
|
SendRun(script []byte) (util.Uint256, uint32, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContractReader implements safe contract methods.
|
||||||
|
type ContractReader struct {
|
||||||
|
invoker Invoker
|
||||||
|
hash util.Uint160
|
||||||
|
}
|
||||||
|
|
||||||
|
// Contract implements all contract methods.
|
||||||
|
type Contract struct {
|
||||||
|
ContractReader
|
||||||
|
actor Actor
|
||||||
|
hash util.Uint160
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewReader creates an instance of ContractReader using provided contract hash and the given Invoker.
|
||||||
|
func NewReader(invoker Invoker, hash util.Uint160) *ContractReader {
|
||||||
|
return &ContractReader{invoker, hash}
|
||||||
|
}
|
||||||
|
|
||||||
|
// New creates an instance of Contract using provided contract hash and the given Actor.
|
||||||
|
func New(actor Actor, hash util.Uint160) *Contract {
|
||||||
|
return &Contract{ContractReader{actor, hash}, actor, hash}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AlphabetAddress invokes `alphabetAddress` method of contract.
|
||||||
|
func (c *ContractReader) AlphabetAddress() (util.Uint160, error) {
|
||||||
|
return unwrap.Uint160(c.invoker.Call(c.hash, "alphabetAddress"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config invokes `config` method of contract.
|
||||||
|
func (c *ContractReader) Config(key []byte) (any, error) {
|
||||||
|
return func(item stackitem.Item, err error) (any, error) {
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return item.Value(), error(nil)
|
||||||
|
}(unwrap.Item(c.invoker.Call(c.hash, "config", key)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// InnerRingCandidates invokes `innerRingCandidates` method of contract.
|
||||||
|
func (c *ContractReader) InnerRingCandidates() ([]stackitem.Item, error) {
|
||||||
|
return unwrap.Array(c.invoker.Call(c.hash, "innerRingCandidates"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListConfig invokes `listConfig` method of contract.
|
||||||
|
func (c *ContractReader) ListConfig() ([]stackitem.Item, error) {
|
||||||
|
return unwrap.Array(c.invoker.Call(c.hash, "listConfig"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Version invokes `version` method of contract.
|
||||||
|
func (c *ContractReader) Version() (*big.Int, error) {
|
||||||
|
return unwrap.BigInt(c.invoker.Call(c.hash, "version"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bind creates a transaction invoking `bind` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) Bind(user []byte, keys []any) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "bind", user, keys)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BindTransaction creates a transaction invoking `bind` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) BindTransaction(user []byte, keys []any) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "bind", user, keys)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BindUnsigned creates a transaction invoking `bind` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) BindUnsigned(user []byte, keys []any) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "bind", nil, user, keys)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cheque creates a transaction invoking `cheque` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) Cheque(id []byte, user util.Uint160, amount *big.Int, lockAcc []byte) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "cheque", id, user, amount, lockAcc)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChequeTransaction creates a transaction invoking `cheque` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) ChequeTransaction(id []byte, user util.Uint160, amount *big.Int, lockAcc []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "cheque", id, user, amount, lockAcc)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChequeUnsigned creates a transaction invoking `cheque` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) ChequeUnsigned(id []byte, user util.Uint160, amount *big.Int, lockAcc []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "cheque", nil, id, user, amount, lockAcc)
|
||||||
|
}
|
||||||
|
|
||||||
|
// InnerRingCandidateAdd creates a transaction invoking `innerRingCandidateAdd` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) InnerRingCandidateAdd(key *keys.PublicKey) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "innerRingCandidateAdd", key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// InnerRingCandidateAddTransaction creates a transaction invoking `innerRingCandidateAdd` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) InnerRingCandidateAddTransaction(key *keys.PublicKey) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "innerRingCandidateAdd", key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// InnerRingCandidateAddUnsigned creates a transaction invoking `innerRingCandidateAdd` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) InnerRingCandidateAddUnsigned(key *keys.PublicKey) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "innerRingCandidateAdd", nil, key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// InnerRingCandidateRemove creates a transaction invoking `innerRingCandidateRemove` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) InnerRingCandidateRemove(key *keys.PublicKey) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "innerRingCandidateRemove", key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// InnerRingCandidateRemoveTransaction creates a transaction invoking `innerRingCandidateRemove` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) InnerRingCandidateRemoveTransaction(key *keys.PublicKey) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "innerRingCandidateRemove", key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// InnerRingCandidateRemoveUnsigned creates a transaction invoking `innerRingCandidateRemove` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) InnerRingCandidateRemoveUnsigned(key *keys.PublicKey) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "innerRingCandidateRemove", nil, key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetConfig creates a transaction invoking `setConfig` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) SetConfig(id []byte, key []byte, val []byte) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "setConfig", id, key, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetConfigTransaction creates a transaction invoking `setConfig` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) SetConfigTransaction(id []byte, key []byte, val []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "setConfig", id, key, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetConfigUnsigned creates a transaction invoking `setConfig` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) SetConfigUnsigned(id []byte, key []byte, val []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "setConfig", nil, id, key, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unbind creates a transaction invoking `unbind` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) Unbind(user []byte, keys []any) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "unbind", user, keys)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnbindTransaction creates a transaction invoking `unbind` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) UnbindTransaction(user []byte, keys []any) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "unbind", user, keys)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnbindUnsigned creates a transaction invoking `unbind` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) UnbindUnsigned(user []byte, keys []any) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "unbind", nil, user, keys)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update creates a transaction invoking `update` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) Update(script []byte, manifest []byte, data any) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "update", script, manifest, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTransaction creates a transaction invoking `update` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) UpdateTransaction(script []byte, manifest []byte, data any) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "update", script, manifest, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUnsigned creates a transaction invoking `update` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) UpdateUnsigned(script []byte, manifest []byte, data any) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "update", nil, script, manifest, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Withdraw creates a transaction invoking `withdraw` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) Withdraw(user util.Uint160, amount *big.Int) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "withdraw", user, amount)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithdrawTransaction creates a transaction invoking `withdraw` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) WithdrawTransaction(user util.Uint160, amount *big.Int) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "withdraw", user, amount)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithdrawUnsigned creates a transaction invoking `withdraw` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) WithdrawUnsigned(user util.Uint160, amount *big.Int) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "withdraw", nil, user, amount)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DepositEventsFromApplicationLog retrieves a set of all emitted events
|
||||||
|
// with "Deposit" name from the provided [result.ApplicationLog].
|
||||||
|
func DepositEventsFromApplicationLog(log *result.ApplicationLog) ([]*DepositEvent, error) {
|
||||||
|
if log == nil {
|
||||||
|
return nil, errors.New("nil application log")
|
||||||
|
}
|
||||||
|
|
||||||
|
var res []*DepositEvent
|
||||||
|
for i, ex := range log.Executions {
|
||||||
|
for j, e := range ex.Events {
|
||||||
|
if e.Name != "Deposit" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
event := new(DepositEvent)
|
||||||
|
err := event.FromStackItem(e.Item)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to deserialize DepositEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
||||||
|
}
|
||||||
|
res = append(res, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromStackItem converts provided [stackitem.Array] to DepositEvent or
|
||||||
|
// returns an error if it's not possible to do to so.
|
||||||
|
func (e *DepositEvent) FromStackItem(item *stackitem.Array) error {
|
||||||
|
if item == nil {
|
||||||
|
return errors.New("nil item")
|
||||||
|
}
|
||||||
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("not an array")
|
||||||
|
}
|
||||||
|
if len(arr) != 4 {
|
||||||
|
return errors.New("wrong number of structure elements")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
index = -1
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
index++
|
||||||
|
e.From, err = func(item stackitem.Item) (util.Uint160, error) {
|
||||||
|
b, err := item.TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, err
|
||||||
|
}
|
||||||
|
u, err := util.Uint160DecodeBytesBE(b)
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, err
|
||||||
|
}
|
||||||
|
return u, nil
|
||||||
|
}(arr[index])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field From: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.Amount, err = arr[index].TryInteger()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field Amount: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.Receiver, err = func(item stackitem.Item) (util.Uint160, error) {
|
||||||
|
b, err := item.TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, err
|
||||||
|
}
|
||||||
|
u, err := util.Uint160DecodeBytesBE(b)
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, err
|
||||||
|
}
|
||||||
|
return u, nil
|
||||||
|
}(arr[index])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field Receiver: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.TxHash, err = func(item stackitem.Item) (util.Uint256, error) {
|
||||||
|
b, err := item.TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint256{}, err
|
||||||
|
}
|
||||||
|
u, err := util.Uint256DecodeBytesBE(b)
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint256{}, err
|
||||||
|
}
|
||||||
|
return u, nil
|
||||||
|
}(arr[index])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field TxHash: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithdrawEventsFromApplicationLog retrieves a set of all emitted events
|
||||||
|
// with "Withdraw" name from the provided [result.ApplicationLog].
|
||||||
|
func WithdrawEventsFromApplicationLog(log *result.ApplicationLog) ([]*WithdrawEvent, error) {
|
||||||
|
if log == nil {
|
||||||
|
return nil, errors.New("nil application log")
|
||||||
|
}
|
||||||
|
|
||||||
|
var res []*WithdrawEvent
|
||||||
|
for i, ex := range log.Executions {
|
||||||
|
for j, e := range ex.Events {
|
||||||
|
if e.Name != "Withdraw" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
event := new(WithdrawEvent)
|
||||||
|
err := event.FromStackItem(e.Item)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to deserialize WithdrawEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
||||||
|
}
|
||||||
|
res = append(res, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromStackItem converts provided [stackitem.Array] to WithdrawEvent or
|
||||||
|
// returns an error if it's not possible to do to so.
|
||||||
|
func (e *WithdrawEvent) FromStackItem(item *stackitem.Array) error {
|
||||||
|
if item == nil {
|
||||||
|
return errors.New("nil item")
|
||||||
|
}
|
||||||
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("not an array")
|
||||||
|
}
|
||||||
|
if len(arr) != 3 {
|
||||||
|
return errors.New("wrong number of structure elements")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
index = -1
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
index++
|
||||||
|
e.User, err = func(item stackitem.Item) (util.Uint160, error) {
|
||||||
|
b, err := item.TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, err
|
||||||
|
}
|
||||||
|
u, err := util.Uint160DecodeBytesBE(b)
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, err
|
||||||
|
}
|
||||||
|
return u, nil
|
||||||
|
}(arr[index])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field User: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.Amount, err = arr[index].TryInteger()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field Amount: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.TxHash, err = func(item stackitem.Item) (util.Uint256, error) {
|
||||||
|
b, err := item.TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint256{}, err
|
||||||
|
}
|
||||||
|
u, err := util.Uint256DecodeBytesBE(b)
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint256{}, err
|
||||||
|
}
|
||||||
|
return u, nil
|
||||||
|
}(arr[index])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field TxHash: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChequeEventsFromApplicationLog retrieves a set of all emitted events
|
||||||
|
// with "Cheque" name from the provided [result.ApplicationLog].
|
||||||
|
func ChequeEventsFromApplicationLog(log *result.ApplicationLog) ([]*ChequeEvent, error) {
|
||||||
|
if log == nil {
|
||||||
|
return nil, errors.New("nil application log")
|
||||||
|
}
|
||||||
|
|
||||||
|
var res []*ChequeEvent
|
||||||
|
for i, ex := range log.Executions {
|
||||||
|
for j, e := range ex.Events {
|
||||||
|
if e.Name != "Cheque" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
event := new(ChequeEvent)
|
||||||
|
err := event.FromStackItem(e.Item)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to deserialize ChequeEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
||||||
|
}
|
||||||
|
res = append(res, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromStackItem converts provided [stackitem.Array] to ChequeEvent or
|
||||||
|
// returns an error if it's not possible to do to so.
|
||||||
|
func (e *ChequeEvent) FromStackItem(item *stackitem.Array) error {
|
||||||
|
if item == nil {
|
||||||
|
return errors.New("nil item")
|
||||||
|
}
|
||||||
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("not an array")
|
||||||
|
}
|
||||||
|
if len(arr) != 4 {
|
||||||
|
return errors.New("wrong number of structure elements")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
index = -1
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
index++
|
||||||
|
e.Id, err = arr[index].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field Id: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.User, err = func(item stackitem.Item) (util.Uint160, error) {
|
||||||
|
b, err := item.TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, err
|
||||||
|
}
|
||||||
|
u, err := util.Uint160DecodeBytesBE(b)
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint160{}, err
|
||||||
|
}
|
||||||
|
return u, nil
|
||||||
|
}(arr[index])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field User: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.Amount, err = arr[index].TryInteger()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field Amount: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.LockAccount, err = arr[index].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field LockAccount: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BindEventsFromApplicationLog retrieves a set of all emitted events
|
||||||
|
// with "Bind" name from the provided [result.ApplicationLog].
|
||||||
|
func BindEventsFromApplicationLog(log *result.ApplicationLog) ([]*BindEvent, error) {
|
||||||
|
if log == nil {
|
||||||
|
return nil, errors.New("nil application log")
|
||||||
|
}
|
||||||
|
|
||||||
|
var res []*BindEvent
|
||||||
|
for i, ex := range log.Executions {
|
||||||
|
for j, e := range ex.Events {
|
||||||
|
if e.Name != "Bind" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
event := new(BindEvent)
|
||||||
|
err := event.FromStackItem(e.Item)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to deserialize BindEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
||||||
|
}
|
||||||
|
res = append(res, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromStackItem converts provided [stackitem.Array] to BindEvent or
|
||||||
|
// returns an error if it's not possible to do to so.
|
||||||
|
func (e *BindEvent) FromStackItem(item *stackitem.Array) error {
|
||||||
|
if item == nil {
|
||||||
|
return errors.New("nil item")
|
||||||
|
}
|
||||||
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("not an array")
|
||||||
|
}
|
||||||
|
if len(arr) != 2 {
|
||||||
|
return errors.New("wrong number of structure elements")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
index = -1
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
index++
|
||||||
|
e.User, err = arr[index].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field User: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.Keys, err = func(item stackitem.Item) ([]any, error) {
|
||||||
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("not an array")
|
||||||
|
}
|
||||||
|
res := make([]any, len(arr))
|
||||||
|
for i := range res {
|
||||||
|
res[i], err = arr[i].Value(), error(nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("item %d: %w", i, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
|
}(arr[index])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field Keys: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnbindEventsFromApplicationLog retrieves a set of all emitted events
|
||||||
|
// with "Unbind" name from the provided [result.ApplicationLog].
|
||||||
|
func UnbindEventsFromApplicationLog(log *result.ApplicationLog) ([]*UnbindEvent, error) {
|
||||||
|
if log == nil {
|
||||||
|
return nil, errors.New("nil application log")
|
||||||
|
}
|
||||||
|
|
||||||
|
var res []*UnbindEvent
|
||||||
|
for i, ex := range log.Executions {
|
||||||
|
for j, e := range ex.Events {
|
||||||
|
if e.Name != "Unbind" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
event := new(UnbindEvent)
|
||||||
|
err := event.FromStackItem(e.Item)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to deserialize UnbindEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
||||||
|
}
|
||||||
|
res = append(res, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromStackItem converts provided [stackitem.Array] to UnbindEvent or
|
||||||
|
// returns an error if it's not possible to do to so.
|
||||||
|
func (e *UnbindEvent) FromStackItem(item *stackitem.Array) error {
|
||||||
|
if item == nil {
|
||||||
|
return errors.New("nil item")
|
||||||
|
}
|
||||||
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("not an array")
|
||||||
|
}
|
||||||
|
if len(arr) != 2 {
|
||||||
|
return errors.New("wrong number of structure elements")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
index = -1
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
index++
|
||||||
|
e.User, err = arr[index].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field User: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.Keys, err = func(item stackitem.Item) ([]any, error) {
|
||||||
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("not an array")
|
||||||
|
}
|
||||||
|
res := make([]any, len(arr))
|
||||||
|
for i := range res {
|
||||||
|
res[i], err = arr[i].Value(), error(nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("item %d: %w", i, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
|
}(arr[index])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field Keys: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AlphabetUpdateEventsFromApplicationLog retrieves a set of all emitted events
|
||||||
|
// with "AlphabetUpdate" name from the provided [result.ApplicationLog].
|
||||||
|
func AlphabetUpdateEventsFromApplicationLog(log *result.ApplicationLog) ([]*AlphabetUpdateEvent, error) {
|
||||||
|
if log == nil {
|
||||||
|
return nil, errors.New("nil application log")
|
||||||
|
}
|
||||||
|
|
||||||
|
var res []*AlphabetUpdateEvent
|
||||||
|
for i, ex := range log.Executions {
|
||||||
|
for j, e := range ex.Events {
|
||||||
|
if e.Name != "AlphabetUpdate" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
event := new(AlphabetUpdateEvent)
|
||||||
|
err := event.FromStackItem(e.Item)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to deserialize AlphabetUpdateEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
||||||
|
}
|
||||||
|
res = append(res, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromStackItem converts provided [stackitem.Array] to AlphabetUpdateEvent or
|
||||||
|
// returns an error if it's not possible to do to so.
|
||||||
|
func (e *AlphabetUpdateEvent) FromStackItem(item *stackitem.Array) error {
|
||||||
|
if item == nil {
|
||||||
|
return errors.New("nil item")
|
||||||
|
}
|
||||||
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("not an array")
|
||||||
|
}
|
||||||
|
if len(arr) != 2 {
|
||||||
|
return errors.New("wrong number of structure elements")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
index = -1
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
index++
|
||||||
|
e.Id, err = arr[index].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field Id: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.Alphabet, err = func(item stackitem.Item) ([]any, error) {
|
||||||
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("not an array")
|
||||||
|
}
|
||||||
|
res := make([]any, len(arr))
|
||||||
|
for i := range res {
|
||||||
|
res[i], err = arr[i].Value(), error(nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("item %d: %w", i, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
|
}(arr[index])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field Alphabet: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetConfigEventsFromApplicationLog retrieves a set of all emitted events
|
||||||
|
// with "SetConfig" name from the provided [result.ApplicationLog].
|
||||||
|
func SetConfigEventsFromApplicationLog(log *result.ApplicationLog) ([]*SetConfigEvent, error) {
|
||||||
|
if log == nil {
|
||||||
|
return nil, errors.New("nil application log")
|
||||||
|
}
|
||||||
|
|
||||||
|
var res []*SetConfigEvent
|
||||||
|
for i, ex := range log.Executions {
|
||||||
|
for j, e := range ex.Events {
|
||||||
|
if e.Name != "SetConfig" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
event := new(SetConfigEvent)
|
||||||
|
err := event.FromStackItem(e.Item)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to deserialize SetConfigEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
||||||
|
}
|
||||||
|
res = append(res, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromStackItem converts provided [stackitem.Array] to SetConfigEvent or
|
||||||
|
// returns an error if it's not possible to do to so.
|
||||||
|
func (e *SetConfigEvent) FromStackItem(item *stackitem.Array) error {
|
||||||
|
if item == nil {
|
||||||
|
return errors.New("nil item")
|
||||||
|
}
|
||||||
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("not an array")
|
||||||
|
}
|
||||||
|
if len(arr) != 3 {
|
||||||
|
return errors.New("wrong number of structure elements")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
index = -1
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
index++
|
||||||
|
e.Id, err = arr[index].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field Id: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.Key, err = arr[index].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field Key: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.Value, err = arr[index].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field Value: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
2044
rpcclient/frostfsid/client.go
Normal file
2044
rpcclient/frostfsid/client.go
Normal file
File diff suppressed because it is too large
Load diff
629
rpcclient/netmap/client.go
Normal file
629
rpcclient/netmap/client.go
Normal file
|
@ -0,0 +1,629 @@
|
||||||
|
// Package netmap contains RPC wrappers for Netmap contract.
|
||||||
|
//
|
||||||
|
// Code generated by neo-go contract generate-rpcwrapper --manifest <file.json> --out <file.go> [--hash <hash>] [--config <config>]; DO NOT EDIT.
|
||||||
|
package netmap
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/elliptic"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
|
"math/big"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AddPeerEvent represents "AddPeer" event emitted by the contract.
|
||||||
|
type AddPeerEvent struct {
|
||||||
|
NodeInfo []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPeerSuccessEvent represents "AddPeerSuccess" event emitted by the contract.
|
||||||
|
type AddPeerSuccessEvent struct {
|
||||||
|
PublicKey *keys.PublicKey
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateStateEvent represents "UpdateState" event emitted by the contract.
|
||||||
|
type UpdateStateEvent struct {
|
||||||
|
State *big.Int
|
||||||
|
PublicKey *keys.PublicKey
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateStateSuccessEvent represents "UpdateStateSuccess" event emitted by the contract.
|
||||||
|
type UpdateStateSuccessEvent struct {
|
||||||
|
PublicKey *keys.PublicKey
|
||||||
|
State *big.Int
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewEpochEvent represents "NewEpoch" event emitted by the contract.
|
||||||
|
type NewEpochEvent struct {
|
||||||
|
Epoch *big.Int
|
||||||
|
}
|
||||||
|
|
||||||
|
// Invoker is used by ContractReader to call various safe methods.
|
||||||
|
type Invoker interface {
|
||||||
|
Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actor is used by Contract to call state-changing methods.
|
||||||
|
type Actor interface {
|
||||||
|
Invoker
|
||||||
|
|
||||||
|
MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error)
|
||||||
|
MakeRun(script []byte) (*transaction.Transaction, error)
|
||||||
|
MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error)
|
||||||
|
MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error)
|
||||||
|
SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error)
|
||||||
|
SendRun(script []byte) (util.Uint256, uint32, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContractReader implements safe contract methods.
|
||||||
|
type ContractReader struct {
|
||||||
|
invoker Invoker
|
||||||
|
hash util.Uint160
|
||||||
|
}
|
||||||
|
|
||||||
|
// Contract implements all contract methods.
|
||||||
|
type Contract struct {
|
||||||
|
ContractReader
|
||||||
|
actor Actor
|
||||||
|
hash util.Uint160
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewReader creates an instance of ContractReader using provided contract hash and the given Invoker.
|
||||||
|
func NewReader(invoker Invoker, hash util.Uint160) *ContractReader {
|
||||||
|
return &ContractReader{invoker, hash}
|
||||||
|
}
|
||||||
|
|
||||||
|
// New creates an instance of Contract using provided contract hash and the given Actor.
|
||||||
|
func New(actor Actor, hash util.Uint160) *Contract {
|
||||||
|
return &Contract{ContractReader{actor, hash}, actor, hash}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config invokes `config` method of contract.
|
||||||
|
func (c *ContractReader) Config(key []byte) (any, error) {
|
||||||
|
return func(item stackitem.Item, err error) (any, error) {
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return item.Value(), error(nil)
|
||||||
|
}(unwrap.Item(c.invoker.Call(c.hash, "config", key)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Epoch invokes `epoch` method of contract.
|
||||||
|
func (c *ContractReader) Epoch() (*big.Int, error) {
|
||||||
|
return unwrap.BigInt(c.invoker.Call(c.hash, "epoch"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListConfig invokes `listConfig` method of contract.
|
||||||
|
func (c *ContractReader) ListConfig() ([]stackitem.Item, error) {
|
||||||
|
return unwrap.Array(c.invoker.Call(c.hash, "listConfig"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Netmap invokes `netmap` method of contract.
|
||||||
|
func (c *ContractReader) Netmap() ([]stackitem.Item, error) {
|
||||||
|
return unwrap.Array(c.invoker.Call(c.hash, "netmap"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NetmapCandidates invokes `netmapCandidates` method of contract.
|
||||||
|
func (c *ContractReader) NetmapCandidates() ([]stackitem.Item, error) {
|
||||||
|
return unwrap.Array(c.invoker.Call(c.hash, "netmapCandidates"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Snapshot invokes `snapshot` method of contract.
|
||||||
|
func (c *ContractReader) Snapshot(diff *big.Int) ([]stackitem.Item, error) {
|
||||||
|
return unwrap.Array(c.invoker.Call(c.hash, "snapshot", diff))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SnapshotByEpoch invokes `snapshotByEpoch` method of contract.
|
||||||
|
func (c *ContractReader) SnapshotByEpoch(epoch *big.Int) ([]stackitem.Item, error) {
|
||||||
|
return unwrap.Array(c.invoker.Call(c.hash, "snapshotByEpoch", epoch))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Version invokes `version` method of contract.
|
||||||
|
func (c *ContractReader) Version() (*big.Int, error) {
|
||||||
|
return unwrap.BigInt(c.invoker.Call(c.hash, "version"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPeer creates a transaction invoking `addPeer` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) AddPeer(nodeInfo []byte) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "addPeer", nodeInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPeerTransaction creates a transaction invoking `addPeer` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) AddPeerTransaction(nodeInfo []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "addPeer", nodeInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPeerUnsigned creates a transaction invoking `addPeer` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) AddPeerUnsigned(nodeInfo []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "addPeer", nil, nodeInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPeerIR creates a transaction invoking `addPeerIR` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) AddPeerIR(nodeInfo []byte) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "addPeerIR", nodeInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPeerIRTransaction creates a transaction invoking `addPeerIR` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) AddPeerIRTransaction(nodeInfo []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "addPeerIR", nodeInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPeerIRUnsigned creates a transaction invoking `addPeerIR` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) AddPeerIRUnsigned(nodeInfo []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "addPeerIR", nil, nodeInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastEpochBlock creates a transaction invoking `lastEpochBlock` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) LastEpochBlock() (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "lastEpochBlock")
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastEpochBlockTransaction creates a transaction invoking `lastEpochBlock` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) LastEpochBlockTransaction() (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "lastEpochBlock")
|
||||||
|
}
|
||||||
|
|
||||||
|
// LastEpochBlockUnsigned creates a transaction invoking `lastEpochBlock` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) LastEpochBlockUnsigned() (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "lastEpochBlock", nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewEpoch creates a transaction invoking `newEpoch` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) NewEpoch(epochNum *big.Int) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "newEpoch", epochNum)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewEpochTransaction creates a transaction invoking `newEpoch` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) NewEpochTransaction(epochNum *big.Int) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "newEpoch", epochNum)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewEpochUnsigned creates a transaction invoking `newEpoch` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) NewEpochUnsigned(epochNum *big.Int) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "newEpoch", nil, epochNum)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetConfig creates a transaction invoking `setConfig` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) SetConfig(id []byte, key []byte, val []byte) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "setConfig", id, key, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetConfigTransaction creates a transaction invoking `setConfig` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) SetConfigTransaction(id []byte, key []byte, val []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "setConfig", id, key, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetConfigUnsigned creates a transaction invoking `setConfig` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) SetConfigUnsigned(id []byte, key []byte, val []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "setConfig", nil, id, key, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update creates a transaction invoking `update` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) Update(script []byte, manifest []byte, data any) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "update", script, manifest, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTransaction creates a transaction invoking `update` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) UpdateTransaction(script []byte, manifest []byte, data any) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "update", script, manifest, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUnsigned creates a transaction invoking `update` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) UpdateUnsigned(script []byte, manifest []byte, data any) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "update", nil, script, manifest, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateSnapshotCount creates a transaction invoking `updateSnapshotCount` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) UpdateSnapshotCount(count *big.Int) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "updateSnapshotCount", count)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateSnapshotCountTransaction creates a transaction invoking `updateSnapshotCount` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) UpdateSnapshotCountTransaction(count *big.Int) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "updateSnapshotCount", count)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateSnapshotCountUnsigned creates a transaction invoking `updateSnapshotCount` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) UpdateSnapshotCountUnsigned(count *big.Int) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "updateSnapshotCount", nil, count)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateState creates a transaction invoking `updateState` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) UpdateState(state *big.Int, publicKey *keys.PublicKey) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "updateState", state, publicKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateStateTransaction creates a transaction invoking `updateState` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) UpdateStateTransaction(state *big.Int, publicKey *keys.PublicKey) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "updateState", state, publicKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateStateUnsigned creates a transaction invoking `updateState` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) UpdateStateUnsigned(state *big.Int, publicKey *keys.PublicKey) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "updateState", nil, state, publicKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateStateIR creates a transaction invoking `updateStateIR` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) UpdateStateIR(state *big.Int, publicKey *keys.PublicKey) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "updateStateIR", state, publicKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateStateIRTransaction creates a transaction invoking `updateStateIR` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) UpdateStateIRTransaction(state *big.Int, publicKey *keys.PublicKey) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "updateStateIR", state, publicKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateStateIRUnsigned creates a transaction invoking `updateStateIR` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) UpdateStateIRUnsigned(state *big.Int, publicKey *keys.PublicKey) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "updateStateIR", nil, state, publicKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPeerEventsFromApplicationLog retrieves a set of all emitted events
|
||||||
|
// with "AddPeer" name from the provided [result.ApplicationLog].
|
||||||
|
func AddPeerEventsFromApplicationLog(log *result.ApplicationLog) ([]*AddPeerEvent, error) {
|
||||||
|
if log == nil {
|
||||||
|
return nil, errors.New("nil application log")
|
||||||
|
}
|
||||||
|
|
||||||
|
var res []*AddPeerEvent
|
||||||
|
for i, ex := range log.Executions {
|
||||||
|
for j, e := range ex.Events {
|
||||||
|
if e.Name != "AddPeer" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
event := new(AddPeerEvent)
|
||||||
|
err := event.FromStackItem(e.Item)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to deserialize AddPeerEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
||||||
|
}
|
||||||
|
res = append(res, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromStackItem converts provided [stackitem.Array] to AddPeerEvent or
|
||||||
|
// returns an error if it's not possible to do to so.
|
||||||
|
func (e *AddPeerEvent) FromStackItem(item *stackitem.Array) error {
|
||||||
|
if item == nil {
|
||||||
|
return errors.New("nil item")
|
||||||
|
}
|
||||||
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("not an array")
|
||||||
|
}
|
||||||
|
if len(arr) != 1 {
|
||||||
|
return errors.New("wrong number of structure elements")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
index = -1
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
index++
|
||||||
|
e.NodeInfo, err = arr[index].TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field NodeInfo: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPeerSuccessEventsFromApplicationLog retrieves a set of all emitted events
|
||||||
|
// with "AddPeerSuccess" name from the provided [result.ApplicationLog].
|
||||||
|
func AddPeerSuccessEventsFromApplicationLog(log *result.ApplicationLog) ([]*AddPeerSuccessEvent, error) {
|
||||||
|
if log == nil {
|
||||||
|
return nil, errors.New("nil application log")
|
||||||
|
}
|
||||||
|
|
||||||
|
var res []*AddPeerSuccessEvent
|
||||||
|
for i, ex := range log.Executions {
|
||||||
|
for j, e := range ex.Events {
|
||||||
|
if e.Name != "AddPeerSuccess" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
event := new(AddPeerSuccessEvent)
|
||||||
|
err := event.FromStackItem(e.Item)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to deserialize AddPeerSuccessEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
||||||
|
}
|
||||||
|
res = append(res, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromStackItem converts provided [stackitem.Array] to AddPeerSuccessEvent or
|
||||||
|
// returns an error if it's not possible to do to so.
|
||||||
|
func (e *AddPeerSuccessEvent) FromStackItem(item *stackitem.Array) error {
|
||||||
|
if item == nil {
|
||||||
|
return errors.New("nil item")
|
||||||
|
}
|
||||||
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("not an array")
|
||||||
|
}
|
||||||
|
if len(arr) != 1 {
|
||||||
|
return errors.New("wrong number of structure elements")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
index = -1
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
index++
|
||||||
|
e.PublicKey, err = func(item stackitem.Item) (*keys.PublicKey, error) {
|
||||||
|
b, err := item.TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
k, err := keys.NewPublicKeyFromBytes(b, elliptic.P256())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return k, nil
|
||||||
|
}(arr[index])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field PublicKey: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateStateEventsFromApplicationLog retrieves a set of all emitted events
|
||||||
|
// with "UpdateState" name from the provided [result.ApplicationLog].
|
||||||
|
func UpdateStateEventsFromApplicationLog(log *result.ApplicationLog) ([]*UpdateStateEvent, error) {
|
||||||
|
if log == nil {
|
||||||
|
return nil, errors.New("nil application log")
|
||||||
|
}
|
||||||
|
|
||||||
|
var res []*UpdateStateEvent
|
||||||
|
for i, ex := range log.Executions {
|
||||||
|
for j, e := range ex.Events {
|
||||||
|
if e.Name != "UpdateState" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
event := new(UpdateStateEvent)
|
||||||
|
err := event.FromStackItem(e.Item)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to deserialize UpdateStateEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
||||||
|
}
|
||||||
|
res = append(res, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromStackItem converts provided [stackitem.Array] to UpdateStateEvent or
|
||||||
|
// returns an error if it's not possible to do to so.
|
||||||
|
func (e *UpdateStateEvent) FromStackItem(item *stackitem.Array) error {
|
||||||
|
if item == nil {
|
||||||
|
return errors.New("nil item")
|
||||||
|
}
|
||||||
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("not an array")
|
||||||
|
}
|
||||||
|
if len(arr) != 2 {
|
||||||
|
return errors.New("wrong number of structure elements")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
index = -1
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
index++
|
||||||
|
e.State, err = arr[index].TryInteger()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field State: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.PublicKey, err = func(item stackitem.Item) (*keys.PublicKey, error) {
|
||||||
|
b, err := item.TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
k, err := keys.NewPublicKeyFromBytes(b, elliptic.P256())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return k, nil
|
||||||
|
}(arr[index])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field PublicKey: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateStateSuccessEventsFromApplicationLog retrieves a set of all emitted events
|
||||||
|
// with "UpdateStateSuccess" name from the provided [result.ApplicationLog].
|
||||||
|
func UpdateStateSuccessEventsFromApplicationLog(log *result.ApplicationLog) ([]*UpdateStateSuccessEvent, error) {
|
||||||
|
if log == nil {
|
||||||
|
return nil, errors.New("nil application log")
|
||||||
|
}
|
||||||
|
|
||||||
|
var res []*UpdateStateSuccessEvent
|
||||||
|
for i, ex := range log.Executions {
|
||||||
|
for j, e := range ex.Events {
|
||||||
|
if e.Name != "UpdateStateSuccess" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
event := new(UpdateStateSuccessEvent)
|
||||||
|
err := event.FromStackItem(e.Item)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to deserialize UpdateStateSuccessEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
||||||
|
}
|
||||||
|
res = append(res, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromStackItem converts provided [stackitem.Array] to UpdateStateSuccessEvent or
|
||||||
|
// returns an error if it's not possible to do to so.
|
||||||
|
func (e *UpdateStateSuccessEvent) FromStackItem(item *stackitem.Array) error {
|
||||||
|
if item == nil {
|
||||||
|
return errors.New("nil item")
|
||||||
|
}
|
||||||
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("not an array")
|
||||||
|
}
|
||||||
|
if len(arr) != 2 {
|
||||||
|
return errors.New("wrong number of structure elements")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
index = -1
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
index++
|
||||||
|
e.PublicKey, err = func(item stackitem.Item) (*keys.PublicKey, error) {
|
||||||
|
b, err := item.TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
k, err := keys.NewPublicKeyFromBytes(b, elliptic.P256())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return k, nil
|
||||||
|
}(arr[index])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field PublicKey: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
index++
|
||||||
|
e.State, err = arr[index].TryInteger()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field State: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewEpochEventsFromApplicationLog retrieves a set of all emitted events
|
||||||
|
// with "NewEpoch" name from the provided [result.ApplicationLog].
|
||||||
|
func NewEpochEventsFromApplicationLog(log *result.ApplicationLog) ([]*NewEpochEvent, error) {
|
||||||
|
if log == nil {
|
||||||
|
return nil, errors.New("nil application log")
|
||||||
|
}
|
||||||
|
|
||||||
|
var res []*NewEpochEvent
|
||||||
|
for i, ex := range log.Executions {
|
||||||
|
for j, e := range ex.Events {
|
||||||
|
if e.Name != "NewEpoch" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
event := new(NewEpochEvent)
|
||||||
|
err := event.FromStackItem(e.Item)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to deserialize NewEpochEvent from stackitem (execution #%d, event #%d): %w", i, j, err)
|
||||||
|
}
|
||||||
|
res = append(res, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromStackItem converts provided [stackitem.Array] to NewEpochEvent or
|
||||||
|
// returns an error if it's not possible to do to so.
|
||||||
|
func (e *NewEpochEvent) FromStackItem(item *stackitem.Array) error {
|
||||||
|
if item == nil {
|
||||||
|
return errors.New("nil item")
|
||||||
|
}
|
||||||
|
arr, ok := item.Value().([]stackitem.Item)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("not an array")
|
||||||
|
}
|
||||||
|
if len(arr) != 1 {
|
||||||
|
return errors.New("wrong number of structure elements")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
index = -1
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
index++
|
||||||
|
e.Epoch, err = arr[index].TryInteger()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("field Epoch: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
336
rpcclient/nns/client.go
Normal file
336
rpcclient/nns/client.go
Normal file
|
@ -0,0 +1,336 @@
|
||||||
|
// Package nameservice contains RPC wrappers for NameService contract.
|
||||||
|
//
|
||||||
|
// Code generated by neo-go contract generate-rpcwrapper --manifest <file.json> --out <file.go> [--hash <hash>] [--config <config>]; DO NOT EDIT.
|
||||||
|
package nameservice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/nep11"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
|
"math/big"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Invoker is used by ContractReader to call various safe methods.
|
||||||
|
type Invoker interface {
|
||||||
|
nep11.Invoker
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actor is used by Contract to call state-changing methods.
|
||||||
|
type Actor interface {
|
||||||
|
Invoker
|
||||||
|
|
||||||
|
nep11.Actor
|
||||||
|
|
||||||
|
MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error)
|
||||||
|
MakeRun(script []byte) (*transaction.Transaction, error)
|
||||||
|
MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error)
|
||||||
|
MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error)
|
||||||
|
SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error)
|
||||||
|
SendRun(script []byte) (util.Uint256, uint32, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContractReader implements safe contract methods.
|
||||||
|
type ContractReader struct {
|
||||||
|
nep11.NonDivisibleReader
|
||||||
|
invoker Invoker
|
||||||
|
hash util.Uint160
|
||||||
|
}
|
||||||
|
|
||||||
|
// Contract implements all contract methods.
|
||||||
|
type Contract struct {
|
||||||
|
ContractReader
|
||||||
|
nep11.BaseWriter
|
||||||
|
actor Actor
|
||||||
|
hash util.Uint160
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewReader creates an instance of ContractReader using provided contract hash and the given Invoker.
|
||||||
|
func NewReader(invoker Invoker, hash util.Uint160) *ContractReader {
|
||||||
|
return &ContractReader{*nep11.NewNonDivisibleReader(invoker, hash), invoker, hash}
|
||||||
|
}
|
||||||
|
|
||||||
|
// New creates an instance of Contract using provided contract hash and the given Actor.
|
||||||
|
func New(actor Actor, hash util.Uint160) *Contract {
|
||||||
|
var nep11ndt = nep11.NewNonDivisible(actor, hash)
|
||||||
|
return &Contract{ContractReader{nep11ndt.NonDivisibleReader, actor, hash}, nep11ndt.BaseWriter, actor, hash}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPrice invokes `getPrice` method of contract.
|
||||||
|
func (c *ContractReader) GetPrice() (*big.Int, error) {
|
||||||
|
return unwrap.BigInt(c.invoker.Call(c.hash, "getPrice"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRecords invokes `getRecords` method of contract.
|
||||||
|
func (c *ContractReader) GetRecords(name string, typ *big.Int) ([]stackitem.Item, error) {
|
||||||
|
return unwrap.Array(c.invoker.Call(c.hash, "getRecords", name, typ))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsAvailable invokes `isAvailable` method of contract.
|
||||||
|
func (c *ContractReader) IsAvailable(name string) (bool, error) {
|
||||||
|
return unwrap.Bool(c.invoker.Call(c.hash, "isAvailable", name))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resolve invokes `resolve` method of contract.
|
||||||
|
func (c *ContractReader) Resolve(name string, typ *big.Int) ([]stackitem.Item, error) {
|
||||||
|
return unwrap.Array(c.invoker.Call(c.hash, "resolve", name, typ))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Roots invokes `roots` method of contract.
|
||||||
|
func (c *ContractReader) Roots() (uuid.UUID, result.Iterator, error) {
|
||||||
|
return unwrap.SessionIterator(c.invoker.Call(c.hash, "roots"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RootsExpanded is similar to Roots (uses the same contract
|
||||||
|
// method), but can be useful if the server used doesn't support sessions and
|
||||||
|
// doesn't expand iterators. It creates a script that will get the specified
|
||||||
|
// number of result items from the iterator right in the VM and return them to
|
||||||
|
// you. It's only limited by VM stack and GAS available for RPC invocations.
|
||||||
|
func (c *ContractReader) RootsExpanded(_numOfIteratorItems int) ([]stackitem.Item, error) {
|
||||||
|
return unwrap.Array(c.invoker.CallAndExpandIterator(c.hash, "roots", _numOfIteratorItems))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Version invokes `version` method of contract.
|
||||||
|
func (c *ContractReader) Version() (*big.Int, error) {
|
||||||
|
return unwrap.BigInt(c.invoker.Call(c.hash, "version"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddRecord creates a transaction invoking `addRecord` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) AddRecord(name string, typ *big.Int, data string) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "addRecord", name, typ, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddRecordTransaction creates a transaction invoking `addRecord` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) AddRecordTransaction(name string, typ *big.Int, data string) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "addRecord", name, typ, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddRecordUnsigned creates a transaction invoking `addRecord` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) AddRecordUnsigned(name string, typ *big.Int, data string) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "addRecord", nil, name, typ, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteRecords creates a transaction invoking `deleteRecords` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) DeleteRecords(name string, typ *big.Int) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "deleteRecords", name, typ)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteRecordsTransaction creates a transaction invoking `deleteRecords` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) DeleteRecordsTransaction(name string, typ *big.Int) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "deleteRecords", name, typ)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteRecordsUnsigned creates a transaction invoking `deleteRecords` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) DeleteRecordsUnsigned(name string, typ *big.Int) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "deleteRecords", nil, name, typ)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAllRecords creates a transaction invoking `getAllRecords` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) GetAllRecords(name string) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "getAllRecords", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAllRecordsTransaction creates a transaction invoking `getAllRecords` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) GetAllRecordsTransaction(name string) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "getAllRecords", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAllRecordsUnsigned creates a transaction invoking `getAllRecords` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) GetAllRecordsUnsigned(name string) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "getAllRecords", nil, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Contract) scriptForRegister(name string, owner util.Uint160, email string, refresh *big.Int, retry *big.Int, expire *big.Int, ttl *big.Int) ([]byte, error) {
|
||||||
|
return smartcontract.CreateCallWithAssertScript(c.hash, "register", name, owner, email, refresh, retry, expire, ttl)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register creates a transaction invoking `register` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) Register(name string, owner util.Uint160, email string, refresh *big.Int, retry *big.Int, expire *big.Int, ttl *big.Int) (util.Uint256, uint32, error) {
|
||||||
|
script, err := c.scriptForRegister(name, owner, email, refresh, retry, expire, ttl)
|
||||||
|
if err != nil {
|
||||||
|
return util.Uint256{}, 0, err
|
||||||
|
}
|
||||||
|
return c.actor.SendRun(script)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterTransaction creates a transaction invoking `register` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) RegisterTransaction(name string, owner util.Uint160, email string, refresh *big.Int, retry *big.Int, expire *big.Int, ttl *big.Int) (*transaction.Transaction, error) {
|
||||||
|
script, err := c.scriptForRegister(name, owner, email, refresh, retry, expire, ttl)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return c.actor.MakeRun(script)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterUnsigned creates a transaction invoking `register` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) RegisterUnsigned(name string, owner util.Uint160, email string, refresh *big.Int, retry *big.Int, expire *big.Int, ttl *big.Int) (*transaction.Transaction, error) {
|
||||||
|
script, err := c.scriptForRegister(name, owner, email, refresh, retry, expire, ttl)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return c.actor.MakeUnsignedRun(script, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Renew creates a transaction invoking `renew` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) Renew(name string) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "renew", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RenewTransaction creates a transaction invoking `renew` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) RenewTransaction(name string) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "renew", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RenewUnsigned creates a transaction invoking `renew` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) RenewUnsigned(name string) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "renew", nil, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAdmin creates a transaction invoking `setAdmin` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) SetAdmin(name string, admin util.Uint160) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "setAdmin", name, admin)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAdminTransaction creates a transaction invoking `setAdmin` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) SetAdminTransaction(name string, admin util.Uint160) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "setAdmin", name, admin)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAdminUnsigned creates a transaction invoking `setAdmin` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) SetAdminUnsigned(name string, admin util.Uint160) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "setAdmin", nil, name, admin)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPrice creates a transaction invoking `setPrice` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) SetPrice(price *big.Int) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "setPrice", price)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPriceTransaction creates a transaction invoking `setPrice` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) SetPriceTransaction(price *big.Int) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "setPrice", price)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPriceUnsigned creates a transaction invoking `setPrice` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) SetPriceUnsigned(price *big.Int) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "setPrice", nil, price)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRecord creates a transaction invoking `setRecord` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) SetRecord(name string, typ *big.Int, id *big.Int, data string) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "setRecord", name, typ, id, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRecordTransaction creates a transaction invoking `setRecord` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) SetRecordTransaction(name string, typ *big.Int, id *big.Int, data string) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "setRecord", name, typ, id, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRecordUnsigned creates a transaction invoking `setRecord` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) SetRecordUnsigned(name string, typ *big.Int, id *big.Int, data string) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "setRecord", nil, name, typ, id, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update creates a transaction invoking `update` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) Update(nef []byte, manifest string, data any) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "update", nef, manifest, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTransaction creates a transaction invoking `update` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) UpdateTransaction(nef []byte, manifest string, data any) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "update", nef, manifest, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUnsigned creates a transaction invoking `update` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) UpdateUnsigned(nef []byte, manifest string, data any) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "update", nil, nef, manifest, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateSOA creates a transaction invoking `updateSOA` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) UpdateSOA(name string, email string, refresh *big.Int, retry *big.Int, expire *big.Int, ttl *big.Int) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "updateSOA", name, email, refresh, retry, expire, ttl)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateSOATransaction creates a transaction invoking `updateSOA` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) UpdateSOATransaction(name string, email string, refresh *big.Int, retry *big.Int, expire *big.Int, ttl *big.Int) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "updateSOA", name, email, refresh, retry, expire, ttl)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateSOAUnsigned creates a transaction invoking `updateSOA` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) UpdateSOAUnsigned(name string, email string, refresh *big.Int, retry *big.Int, expire *big.Int, ttl *big.Int) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "updateSOA", nil, name, email, refresh, retry, expire, ttl)
|
||||||
|
}
|
161
rpcclient/policy/client.go
Normal file
161
rpcclient/policy/client.go
Normal file
|
@ -0,0 +1,161 @@
|
||||||
|
// Package ape contains RPC wrappers for APE contract.
|
||||||
|
//
|
||||||
|
// Code generated by neo-go contract generate-rpcwrapper --manifest <file.json> --out <file.go> [--hash <hash>] [--config <config>]; DO NOT EDIT.
|
||||||
|
package ape
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
|
"math/big"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Invoker is used by ContractReader to call various safe methods.
|
||||||
|
type Invoker interface {
|
||||||
|
Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actor is used by Contract to call state-changing methods.
|
||||||
|
type Actor interface {
|
||||||
|
Invoker
|
||||||
|
|
||||||
|
MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error)
|
||||||
|
MakeRun(script []byte) (*transaction.Transaction, error)
|
||||||
|
MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error)
|
||||||
|
MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error)
|
||||||
|
SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error)
|
||||||
|
SendRun(script []byte) (util.Uint256, uint32, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContractReader implements safe contract methods.
|
||||||
|
type ContractReader struct {
|
||||||
|
invoker Invoker
|
||||||
|
hash util.Uint160
|
||||||
|
}
|
||||||
|
|
||||||
|
// Contract implements all contract methods.
|
||||||
|
type Contract struct {
|
||||||
|
ContractReader
|
||||||
|
actor Actor
|
||||||
|
hash util.Uint160
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewReader creates an instance of ContractReader using provided contract hash and the given Invoker.
|
||||||
|
func NewReader(invoker Invoker, hash util.Uint160) *ContractReader {
|
||||||
|
return &ContractReader{invoker, hash}
|
||||||
|
}
|
||||||
|
|
||||||
|
// New creates an instance of Contract using provided contract hash and the given Actor.
|
||||||
|
func New(actor Actor, hash util.Uint160) *Contract {
|
||||||
|
return &Contract{ContractReader{actor, hash}, actor, hash}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAdmin invokes `getAdmin` method of contract.
|
||||||
|
func (c *ContractReader) GetAdmin() (util.Uint160, error) {
|
||||||
|
return unwrap.Uint160(c.invoker.Call(c.hash, "getAdmin"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetChain invokes `getChain` method of contract.
|
||||||
|
func (c *ContractReader) GetChain(entity *big.Int, entityName string, name []byte) ([]byte, error) {
|
||||||
|
return unwrap.Bytes(c.invoker.Call(c.hash, "getChain", entity, entityName, name))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListChains invokes `listChains` method of contract.
|
||||||
|
func (c *ContractReader) ListChains(namespace string, container string, name []byte) ([]stackitem.Item, error) {
|
||||||
|
return unwrap.Array(c.invoker.Call(c.hash, "listChains", namespace, container, name))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListChainsByPrefix invokes `listChainsByPrefix` method of contract.
|
||||||
|
func (c *ContractReader) ListChainsByPrefix(entity *big.Int, entityName string, prefix []byte) ([]stackitem.Item, error) {
|
||||||
|
return unwrap.Array(c.invoker.Call(c.hash, "listChainsByPrefix", entity, entityName, prefix))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddChain creates a transaction invoking `addChain` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) AddChain(entity *big.Int, entityName string, name []byte, chain []byte) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "addChain", entity, entityName, name, chain)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddChainTransaction creates a transaction invoking `addChain` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) AddChainTransaction(entity *big.Int, entityName string, name []byte, chain []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "addChain", entity, entityName, name, chain)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddChainUnsigned creates a transaction invoking `addChain` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) AddChainUnsigned(entity *big.Int, entityName string, name []byte, chain []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "addChain", nil, entity, entityName, name, chain)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveChain creates a transaction invoking `removeChain` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) RemoveChain(entity *big.Int, entityName string, name []byte) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "removeChain", entity, entityName, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveChainTransaction creates a transaction invoking `removeChain` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) RemoveChainTransaction(entity *big.Int, entityName string, name []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "removeChain", entity, entityName, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveChainUnsigned creates a transaction invoking `removeChain` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) RemoveChainUnsigned(entity *big.Int, entityName string, name []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "removeChain", nil, entity, entityName, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveChainsByPrefix creates a transaction invoking `removeChainsByPrefix` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) RemoveChainsByPrefix(entity *big.Int, entityName string, name []byte) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "removeChainsByPrefix", entity, entityName, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveChainsByPrefixTransaction creates a transaction invoking `removeChainsByPrefix` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) RemoveChainsByPrefixTransaction(entity *big.Int, entityName string, name []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "removeChainsByPrefix", entity, entityName, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveChainsByPrefixUnsigned creates a transaction invoking `removeChainsByPrefix` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) RemoveChainsByPrefixUnsigned(entity *big.Int, entityName string, name []byte) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "removeChainsByPrefix", nil, entity, entityName, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAdmin creates a transaction invoking `setAdmin` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) SetAdmin(addr util.Uint160) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "setAdmin", addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAdminTransaction creates a transaction invoking `setAdmin` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) SetAdminTransaction(addr util.Uint160) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "setAdmin", addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAdminUnsigned creates a transaction invoking `setAdmin` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) SetAdminUnsigned(addr util.Uint160) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "setAdmin", nil, addr)
|
||||||
|
}
|
84
rpcclient/processing/client.go
Normal file
84
rpcclient/processing/client.go
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
// Package multisignatureprocessing contains RPC wrappers for Multi Signature Processing contract.
|
||||||
|
//
|
||||||
|
// Code generated by neo-go contract generate-rpcwrapper --manifest <file.json> --out <file.go> [--hash <hash>] [--config <config>]; DO NOT EDIT.
|
||||||
|
package multisignatureprocessing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"math/big"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Invoker is used by ContractReader to call various safe methods.
|
||||||
|
type Invoker interface {
|
||||||
|
Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actor is used by Contract to call state-changing methods.
|
||||||
|
type Actor interface {
|
||||||
|
Invoker
|
||||||
|
|
||||||
|
MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error)
|
||||||
|
MakeRun(script []byte) (*transaction.Transaction, error)
|
||||||
|
MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error)
|
||||||
|
MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error)
|
||||||
|
SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error)
|
||||||
|
SendRun(script []byte) (util.Uint256, uint32, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContractReader implements safe contract methods.
|
||||||
|
type ContractReader struct {
|
||||||
|
invoker Invoker
|
||||||
|
hash util.Uint160
|
||||||
|
}
|
||||||
|
|
||||||
|
// Contract implements all contract methods.
|
||||||
|
type Contract struct {
|
||||||
|
ContractReader
|
||||||
|
actor Actor
|
||||||
|
hash util.Uint160
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewReader creates an instance of ContractReader using provided contract hash and the given Invoker.
|
||||||
|
func NewReader(invoker Invoker, hash util.Uint160) *ContractReader {
|
||||||
|
return &ContractReader{invoker, hash}
|
||||||
|
}
|
||||||
|
|
||||||
|
// New creates an instance of Contract using provided contract hash and the given Actor.
|
||||||
|
func New(actor Actor, hash util.Uint160) *Contract {
|
||||||
|
return &Contract{ContractReader{actor, hash}, actor, hash}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify invokes `verify` method of contract.
|
||||||
|
func (c *ContractReader) Verify() (bool, error) {
|
||||||
|
return unwrap.Bool(c.invoker.Call(c.hash, "verify"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Version invokes `version` method of contract.
|
||||||
|
func (c *ContractReader) Version() (*big.Int, error) {
|
||||||
|
return unwrap.BigInt(c.invoker.Call(c.hash, "version"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update creates a transaction invoking `update` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) Update(script []byte, manifest []byte, data any) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "update", script, manifest, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTransaction creates a transaction invoking `update` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) UpdateTransaction(script []byte, manifest []byte, data any) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "update", script, manifest, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUnsigned creates a transaction invoking `update` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) UpdateUnsigned(script []byte, manifest []byte, data any) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "update", nil, script, manifest, data)
|
||||||
|
}
|
84
rpcclient/proxy/client.go
Normal file
84
rpcclient/proxy/client.go
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
// Package notaryproxy contains RPC wrappers for Notary Proxy contract.
|
||||||
|
//
|
||||||
|
// Code generated by neo-go contract generate-rpcwrapper --manifest <file.json> --out <file.go> [--hash <hash>] [--config <config>]; DO NOT EDIT.
|
||||||
|
package notaryproxy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"math/big"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Invoker is used by ContractReader to call various safe methods.
|
||||||
|
type Invoker interface {
|
||||||
|
Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actor is used by Contract to call state-changing methods.
|
||||||
|
type Actor interface {
|
||||||
|
Invoker
|
||||||
|
|
||||||
|
MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error)
|
||||||
|
MakeRun(script []byte) (*transaction.Transaction, error)
|
||||||
|
MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error)
|
||||||
|
MakeUnsignedRun(script []byte, attrs []transaction.Attribute) (*transaction.Transaction, error)
|
||||||
|
SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error)
|
||||||
|
SendRun(script []byte) (util.Uint256, uint32, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContractReader implements safe contract methods.
|
||||||
|
type ContractReader struct {
|
||||||
|
invoker Invoker
|
||||||
|
hash util.Uint160
|
||||||
|
}
|
||||||
|
|
||||||
|
// Contract implements all contract methods.
|
||||||
|
type Contract struct {
|
||||||
|
ContractReader
|
||||||
|
actor Actor
|
||||||
|
hash util.Uint160
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewReader creates an instance of ContractReader using provided contract hash and the given Invoker.
|
||||||
|
func NewReader(invoker Invoker, hash util.Uint160) *ContractReader {
|
||||||
|
return &ContractReader{invoker, hash}
|
||||||
|
}
|
||||||
|
|
||||||
|
// New creates an instance of Contract using provided contract hash and the given Actor.
|
||||||
|
func New(actor Actor, hash util.Uint160) *Contract {
|
||||||
|
return &Contract{ContractReader{actor, hash}, actor, hash}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify invokes `verify` method of contract.
|
||||||
|
func (c *ContractReader) Verify() (bool, error) {
|
||||||
|
return unwrap.Bool(c.invoker.Call(c.hash, "verify"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Version invokes `version` method of contract.
|
||||||
|
func (c *ContractReader) Version() (*big.Int, error) {
|
||||||
|
return unwrap.BigInt(c.invoker.Call(c.hash, "version"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update creates a transaction invoking `update` method of the contract.
|
||||||
|
// This transaction is signed and immediately sent to the network.
|
||||||
|
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||||
|
func (c *Contract) Update(script []byte, manifest []byte, data any) (util.Uint256, uint32, error) {
|
||||||
|
return c.actor.SendCall(c.hash, "update", script, manifest, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTransaction creates a transaction invoking `update` method of the contract.
|
||||||
|
// This transaction is signed, but not sent to the network, instead it's
|
||||||
|
// returned to the caller.
|
||||||
|
func (c *Contract) UpdateTransaction(script []byte, manifest []byte, data any) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeCall(c.hash, "update", script, manifest, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUnsigned creates a transaction invoking `update` method of the contract.
|
||||||
|
// This transaction is not signed, it's simply returned to the caller.
|
||||||
|
// Any fields of it that do not affect fees can be changed (ValidUntilBlock,
|
||||||
|
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||||
|
func (c *Contract) UpdateUnsigned(script []byte, manifest []byte, data any) (*transaction.Transaction, error) {
|
||||||
|
return c.actor.MakeUnsignedCall(c.hash, "update", nil, script, manifest, data)
|
||||||
|
}
|
|
@ -21,13 +21,12 @@ const alphabetPath = "../alphabet"
|
||||||
func deployAlphabetContract(t *testing.T, e *neotest.Executor, addrNetmap, addrProxy util.Uint160, name string, index, total int64) util.Uint160 {
|
func deployAlphabetContract(t *testing.T, e *neotest.Executor, addrNetmap, addrProxy util.Uint160, name string, index, total int64) util.Uint160 {
|
||||||
c := neotest.CompileFile(t, e.CommitteeHash, alphabetPath, path.Join(alphabetPath, "config.yml"))
|
c := neotest.CompileFile(t, e.CommitteeHash, alphabetPath, path.Join(alphabetPath, "config.yml"))
|
||||||
|
|
||||||
args := make([]interface{}, 6)
|
args := make([]any, 5)
|
||||||
args[0] = false
|
args[0] = addrNetmap
|
||||||
args[1] = addrNetmap
|
args[1] = addrProxy
|
||||||
args[2] = addrProxy
|
args[2] = name
|
||||||
args[3] = name
|
args[3] = index
|
||||||
args[4] = index
|
args[4] = total
|
||||||
args[5] = total
|
|
||||||
|
|
||||||
e.DeployContract(t, c, args)
|
e.DeployContract(t, c, args)
|
||||||
return c.Hash
|
return c.Hash
|
||||||
|
@ -88,8 +87,8 @@ func TestVote(t *testing.T) {
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
cNewAlphabet := c.WithSigners(newAlphabet)
|
cNewAlphabet := c.WithSigners(newAlphabet)
|
||||||
|
|
||||||
cNewAlphabet.InvokeFail(t, common.ErrAlphabetWitnessFailed, method, int64(0), []interface{}{newAlphabetPub})
|
cNewAlphabet.InvokeFail(t, common.ErrAlphabetWitnessFailed, method, int64(0), []any{newAlphabetPub})
|
||||||
c.InvokeFail(t, "invalid epoch", method, int64(1), []interface{}{newAlphabetPub})
|
c.InvokeFail(t, "invalid epoch", method, int64(1), []any{newAlphabetPub})
|
||||||
|
|
||||||
setAlphabetRole(t, e, newAlphabetPub)
|
setAlphabetRole(t, e, newAlphabetPub)
|
||||||
transferNeoToContract(t, c)
|
transferNeoToContract(t, c)
|
||||||
|
@ -109,7 +108,7 @@ func TestVote(t *testing.T) {
|
||||||
newInvoker := neoInvoker.WithSigners(newAlphabet)
|
newInvoker := neoInvoker.WithSigners(newAlphabet)
|
||||||
|
|
||||||
newInvoker.Invoke(t, stackitem.NewBool(true), "registerCandidate", newAlphabetPub)
|
newInvoker.Invoke(t, stackitem.NewBool(true), "registerCandidate", newAlphabetPub)
|
||||||
c.Invoke(t, stackitem.Null{}, method, int64(0), []interface{}{newAlphabetPub})
|
c.Invoke(t, stackitem.Null{}, method, int64(0), []any{newAlphabetPub})
|
||||||
|
|
||||||
// wait one block util
|
// wait one block util
|
||||||
// a new committee is accepted
|
// a new committee is accepted
|
||||||
|
@ -139,7 +138,7 @@ func setAlphabetRole(t *testing.T, e *neotest.Executor, new []byte) {
|
||||||
designInvoker := e.CommitteeInvoker(designSH)
|
designInvoker := e.CommitteeInvoker(designSH)
|
||||||
|
|
||||||
// set committee as NeoFSAlphabet
|
// set committee as NeoFSAlphabet
|
||||||
designInvoker.Invoke(t, stackitem.Null{}, "designateAsRole", int64(noderoles.NeoFSAlphabet), []interface{}{new})
|
designInvoker.Invoke(t, stackitem.Null{}, "designateAsRole", int64(noderoles.NeoFSAlphabet), []any{new})
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAlphabetAcc(t *testing.T, e *neotest.Executor) *wallet.Account {
|
func getAlphabetAcc(t *testing.T, e *neotest.Executor) *wallet.Account {
|
||||||
|
|
|
@ -14,10 +14,9 @@ const balancePath = "../balance"
|
||||||
func deployBalanceContract(t *testing.T, e *neotest.Executor, addrNetmap, addrContainer util.Uint160) util.Uint160 {
|
func deployBalanceContract(t *testing.T, e *neotest.Executor, addrNetmap, addrContainer util.Uint160) util.Uint160 {
|
||||||
c := neotest.CompileFile(t, e.CommitteeHash, balancePath, path.Join(balancePath, "config.yml"))
|
c := neotest.CompileFile(t, e.CommitteeHash, balancePath, path.Join(balancePath, "config.yml"))
|
||||||
|
|
||||||
args := make([]interface{}, 3)
|
args := make([]any, 3)
|
||||||
args[0] = false
|
args[0] = addrNetmap
|
||||||
args[1] = addrNetmap
|
args[1] = addrContainer
|
||||||
args[2] = addrContainer
|
|
||||||
|
|
||||||
e.DeployContract(t, c, args)
|
e.DeployContract(t, c, args)
|
||||||
return c.Hash
|
return c.Hash
|
||||||
|
|
61
tests/common_test.go
Normal file
61
tests/common_test.go
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
package tests
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math"
|
||||||
|
"math/big"
|
||||||
|
"path"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/neotest"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
const testdataPath = "./testdata"
|
||||||
|
|
||||||
|
func newTestdataInvoker(t *testing.T) *neotest.ContractInvoker {
|
||||||
|
e := newExecutor(t)
|
||||||
|
ctr := neotest.CompileFile(t, e.CommitteeHash, testdataPath, path.Join(testdataPath, "config.yml"))
|
||||||
|
e.DeployContract(t, ctr, nil)
|
||||||
|
return e.CommitteeInvoker(ctr.Hash)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEncodeU64(t *testing.T) {
|
||||||
|
// Let's check boundary values for all bit sizes:
|
||||||
|
var nums []uint64
|
||||||
|
for i := 0; i < 64; i++ {
|
||||||
|
if i != 0 {
|
||||||
|
nums = append(nums, (1<<i)-1)
|
||||||
|
}
|
||||||
|
nums = append(nums, 1<<i)
|
||||||
|
if i != 63 {
|
||||||
|
nums = append(nums, (1<<i)+1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c := newTestdataInvoker(t)
|
||||||
|
for _, n := range nums {
|
||||||
|
v, err := c.TestInvoke(t, "encode", n)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, 1, v.Len())
|
||||||
|
|
||||||
|
r := v.Pop().Bytes()
|
||||||
|
require.Equal(t, 9, len(r), "got: %x", r)
|
||||||
|
|
||||||
|
v, err = c.TestInvoke(t, "encodeDecode", n)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, 1, v.Len())
|
||||||
|
require.Equal(t, n, v.Pop().BigInt().Uint64())
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run("bad cases should be handled", func(t *testing.T) {
|
||||||
|
x := new(big.Int).SetUint64(math.MaxUint64)
|
||||||
|
x.Add(x, big.NewInt(1))
|
||||||
|
|
||||||
|
nums := []*big.Int{x, big.NewInt(-1), big.NewInt(-128)}
|
||||||
|
for _, n := range nums {
|
||||||
|
v, err := c.TestInvoke(t, "encodeDecode", n)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, 0, v.Pop().BigInt().Cmp(n))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ package tests
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -12,6 +13,7 @@ import (
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-contract/nns"
|
"git.frostfs.info/TrueCloudLab/frostfs-contract/nns"
|
||||||
"github.com/mr-tron/base58"
|
"github.com/mr-tron/base58"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop/storage"
|
"github.com/nspcc-dev/neo-go/pkg/core/interop/storage"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/neotest"
|
"github.com/nspcc-dev/neo-go/pkg/neotest"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
@ -22,18 +24,17 @@ import (
|
||||||
const containerPath = "../container"
|
const containerPath = "../container"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
containerFee = 0_0100_0000
|
containerFee = 0o_0100_0000
|
||||||
containerAliasFee = 0_0050_0000
|
containerAliasFee = 0o_0050_0000
|
||||||
)
|
)
|
||||||
|
|
||||||
func deployContainerContract(t *testing.T, e *neotest.Executor, addrNetmap, addrBalance, addrNNS util.Uint160) util.Uint160 {
|
func deployContainerContract(t *testing.T, e *neotest.Executor, addrNetmap, addrBalance, addrNNS util.Uint160) util.Uint160 {
|
||||||
args := make([]interface{}, 6)
|
args := make([]any, 5)
|
||||||
args[0] = int64(0)
|
args[0] = addrNetmap
|
||||||
args[1] = addrNetmap
|
args[1] = addrBalance
|
||||||
args[2] = addrBalance
|
args[2] = util.Uint160{} // not needed for now
|
||||||
args[3] = util.Uint160{} // not needed for now
|
args[3] = addrNNS
|
||||||
args[4] = addrNNS
|
args[4] = "frostfs"
|
||||||
args[5] = "frostfs"
|
|
||||||
|
|
||||||
c := neotest.CompileFile(t, e.CommitteeHash, containerPath, path.Join(containerPath, "config.yml"))
|
c := neotest.CompileFile(t, e.CommitteeHash, containerPath, path.Join(containerPath, "config.yml"))
|
||||||
e.DeployContract(t, c, args)
|
e.DeployContract(t, c, args)
|
||||||
|
@ -162,7 +163,6 @@ func checkContainerList(t *testing.T, c *neotest.ContractInvoker, expected [][]b
|
||||||
}
|
}
|
||||||
require.ElementsMatch(t, expected, actual)
|
require.ElementsMatch(t, expected, actual)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContainerPut(t *testing.T) {
|
func TestContainerPut(t *testing.T) {
|
||||||
|
@ -171,7 +171,7 @@ func TestContainerPut(t *testing.T) {
|
||||||
acc := c.NewAccount(t)
|
acc := c.NewAccount(t)
|
||||||
cnt := dummyContainer(acc)
|
cnt := dummyContainer(acc)
|
||||||
|
|
||||||
putArgs := []interface{}{cnt.value, cnt.sig, cnt.pub, cnt.token}
|
putArgs := []any{cnt.value, cnt.sig, cnt.pub, cnt.token}
|
||||||
c.InvokeFail(t, "insufficient balance to create container", "put", putArgs...)
|
c.InvokeFail(t, "insufficient balance to create container", "put", putArgs...)
|
||||||
|
|
||||||
balanceMint(t, cBal, acc, containerFee*1, []byte{})
|
balanceMint(t, cBal, acc, containerFee*1, []byte{})
|
||||||
|
@ -187,7 +187,7 @@ func TestContainerPut(t *testing.T) {
|
||||||
|
|
||||||
balanceMint(t, cBal, acc, containerFee*1, []byte{})
|
balanceMint(t, cBal, acc, containerFee*1, []byte{})
|
||||||
|
|
||||||
putArgs := []interface{}{cnt.value, cnt.sig, cnt.pub, cnt.token, "mycnt", ""}
|
putArgs := []any{cnt.value, cnt.sig, cnt.pub, cnt.token, "mycnt", ""}
|
||||||
t.Run("no fee for alias", func(t *testing.T) {
|
t.Run("no fee for alias", func(t *testing.T) {
|
||||||
c.InvokeFail(t, "insufficient balance to create container", "putNamed", putArgs...)
|
c.InvokeFail(t, "insufficient balance to create container", "putNamed", putArgs...)
|
||||||
})
|
})
|
||||||
|
@ -222,15 +222,44 @@ func TestContainerPut(t *testing.T) {
|
||||||
|
|
||||||
balanceMint(t, cBal, acc, (containerFee+containerAliasFee)*1, []byte{})
|
balanceMint(t, cBal, acc, (containerFee+containerAliasFee)*1, []byte{})
|
||||||
|
|
||||||
putArgs := []interface{}{cnt.value, cnt.sig, cnt.pub, cnt.token, "domain", "cdn"}
|
putArgs := []any{cnt.value, cnt.sig, cnt.pub, cnt.token, "domain", "cdn"}
|
||||||
c2 := c.WithSigners(c.Committee, acc)
|
c2 := c.WithSigners(c.Committee, acc)
|
||||||
c2.Invoke(t, stackitem.Null{}, "putNamed", putArgs...)
|
c2.Invoke(t, stackitem.Null{}, "putNamed", putArgs...)
|
||||||
|
|
||||||
expected = stackitem.NewArray([]stackitem.Item{
|
expected = stackitem.NewArray([]stackitem.Item{
|
||||||
stackitem.NewByteArray([]byte(base58.Encode(cnt.id[:])))})
|
stackitem.NewByteArray([]byte(base58.Encode(cnt.id[:]))),
|
||||||
|
})
|
||||||
cNNS.Invoke(t, expected, "resolve", "domain.cdn", int64(nns.TXT))
|
cNNS.Invoke(t, expected, "resolve", "domain.cdn", int64(nns.TXT))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("gas costs are the same for all containers in block", func(t *testing.T) {
|
||||||
|
const (
|
||||||
|
containerPerBlock = 512
|
||||||
|
totalContainers = containerPerBlock + 1
|
||||||
|
totalPrice = containerFee + containerAliasFee
|
||||||
|
)
|
||||||
|
|
||||||
|
acc := c.NewAccount(t)
|
||||||
|
balanceMint(t, cBal, acc, totalPrice*totalContainers, []byte{})
|
||||||
|
cnt := dummyContainer(acc)
|
||||||
|
putArgs := []any{cnt.value, cnt.sig, cnt.pub, cnt.token, "precreated", ""}
|
||||||
|
c.Invoke(t, stackitem.Null{}, "putNamed", putArgs...)
|
||||||
|
|
||||||
|
txs := make([]*transaction.Transaction, 0, containerPerBlock)
|
||||||
|
for i := 0; i < containerPerBlock; i++ {
|
||||||
|
cnt := dummyContainer(acc)
|
||||||
|
name := fmt.Sprintf("name-%.5d", i)
|
||||||
|
tx := c.PrepareInvoke(t, "putNamed", cnt.value, cnt.sig, cnt.pub, cnt.token, name, "")
|
||||||
|
txs = append(txs, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.AddNewBlock(t, txs...)
|
||||||
|
|
||||||
|
for i := 0; i < containerPerBlock; i++ {
|
||||||
|
c.CheckHalt(t, txs[i].Hash(), stackitem.Make(stackitem.Null{}))
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func addContainer(t *testing.T, c, cBal *neotest.ContractInvoker) (neotest.Signer, testContainer) {
|
func addContainer(t *testing.T, c, cBal *neotest.ContractInvoker) (neotest.Signer, testContainer) {
|
||||||
|
@ -282,6 +311,30 @@ func TestContainerDelete(t *testing.T) {
|
||||||
c.InvokeFail(t, container.NotFoundError, "deletionInfo", id[:])
|
c.InvokeFail(t, container.NotFoundError, "deletionInfo", id[:])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("gas costs are the same for different epochs", func(t *testing.T) {
|
||||||
|
_, cnt2 := addContainer(t, c, cBal)
|
||||||
|
args := []any{cnt2.id[:], cnt2.sig, cnt2.pub, cnt2.token}
|
||||||
|
|
||||||
|
tx := c.PrepareInvoke(t, "delete", args...)
|
||||||
|
for _, e := range []int{126, 127, 128, 129, 65536} {
|
||||||
|
cNm.Invoke(t, stackitem.Null{}, "newEpoch", e)
|
||||||
|
|
||||||
|
// Sanity check.
|
||||||
|
s, err := cNm.TestInvoke(t, "epoch")
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, big.NewInt(int64(e)), s.Top().BigInt())
|
||||||
|
|
||||||
|
tx2 := c.PrepareInvoke(t, "delete", args...)
|
||||||
|
require.Equal(t, tx.Size(), tx2.Size())
|
||||||
|
require.Equal(t, tx.SystemFee, tx2.SystemFee)
|
||||||
|
require.Equal(t, tx.NetworkFee, tx2.NetworkFee)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Another sanity check: we want to test successful invocations,
|
||||||
|
// bad ones can trivially be equal.
|
||||||
|
c.Invoke(t, stackitem.Null{}, "delete", args...)
|
||||||
|
})
|
||||||
|
|
||||||
c.InvokeFail(t, container.NotFoundError, "get", cnt.id[:])
|
c.InvokeFail(t, container.NotFoundError, "get", cnt.id[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,7 +404,7 @@ func TestContainerSetEACL(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
e := dummyEACL(cnt.id)
|
e := dummyEACL(cnt.id)
|
||||||
setArgs := []interface{}{e.value, e.sig, e.pub, e.token}
|
setArgs := []any{e.value, e.sig, e.pub, e.token}
|
||||||
cAcc := c.WithSigners(acc)
|
cAcc := c.WithSigners(acc)
|
||||||
cAcc.InvokeFail(t, common.ErrAlphabetWitnessFailed, "setEACL", setArgs...)
|
cAcc.InvokeFail(t, common.ErrAlphabetWitnessFailed, "setEACL", setArgs...)
|
||||||
|
|
||||||
|
|
|
@ -21,24 +21,24 @@ import (
|
||||||
const frostfsPath = "../frostfs"
|
const frostfsPath = "../frostfs"
|
||||||
|
|
||||||
func deployFrostFSContract(t *testing.T, e *neotest.Executor, addrProc util.Uint160,
|
func deployFrostFSContract(t *testing.T, e *neotest.Executor, addrProc util.Uint160,
|
||||||
pubs keys.PublicKeys, config ...interface{}) util.Uint160 {
|
pubs keys.PublicKeys, config ...any,
|
||||||
args := make([]interface{}, 5)
|
) util.Uint160 {
|
||||||
args[0] = false
|
args := make([]any, 3)
|
||||||
args[1] = addrProc
|
args[0] = addrProc
|
||||||
|
|
||||||
arr := make([]interface{}, len(pubs))
|
arr := make([]any, len(pubs))
|
||||||
for i := range pubs {
|
for i := range pubs {
|
||||||
arr[i] = pubs[i].Bytes()
|
arr[i] = pubs[i].Bytes()
|
||||||
}
|
}
|
||||||
args[2] = arr
|
args[1] = arr
|
||||||
args[3] = append([]interface{}{}, config...)
|
args[2] = append([]any{}, config...)
|
||||||
|
|
||||||
c := neotest.CompileFile(t, e.CommitteeHash, frostfsPath, path.Join(frostfsPath, "config.yml"))
|
c := neotest.CompileFile(t, e.CommitteeHash, frostfsPath, path.Join(frostfsPath, "config.yml"))
|
||||||
e.DeployContract(t, c, args)
|
e.DeployContract(t, c, args)
|
||||||
return c.Hash
|
return c.Hash
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFrostFSInvoker(t *testing.T, n int, config ...interface{}) (*neotest.ContractInvoker, neotest.Signer, keys.PublicKeys) {
|
func newFrostFSInvoker(t *testing.T, n int, config ...any) (*neotest.ContractInvoker, neotest.Signer, keys.PublicKeys) {
|
||||||
e := newExecutor(t)
|
e := newExecutor(t)
|
||||||
|
|
||||||
accounts := make([]*wallet.Account, n)
|
accounts := make([]*wallet.Account, n)
|
||||||
|
|
537
tests/frostfsid_client_test.go
Normal file
537
tests/frostfsid_client_test.go
Normal file
|
@ -0,0 +1,537 @@
|
||||||
|
package tests
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-contract/frostfsid/client"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
type testFrostFSIDClientInvoker struct {
|
||||||
|
base *testFrostFSIDInvoker
|
||||||
|
cli *client.Client
|
||||||
|
a awaiter
|
||||||
|
}
|
||||||
|
|
||||||
|
func initFrostfsIFClientTest(t *testing.T) (clientInvoker *testFrostFSIDClientInvoker, cancelFn func()) {
|
||||||
|
f := newFrostFSIDInvoker(t)
|
||||||
|
|
||||||
|
wlt := initTmpWallet(t)
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
address := runRPC(ctx, t, f.e.Chain, wlt)
|
||||||
|
|
||||||
|
cli, rpc := frostfsidRPCClient(t, address, f.contractHash, f.owner)
|
||||||
|
|
||||||
|
clientInvoker = &testFrostFSIDClientInvoker{
|
||||||
|
base: f,
|
||||||
|
cli: cli,
|
||||||
|
a: awaiter{
|
||||||
|
ctx: ctx,
|
||||||
|
t: t,
|
||||||
|
rpc: rpc,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return clientInvoker, func() {
|
||||||
|
cancel()
|
||||||
|
err := os.Remove(wlt)
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func frostfsidRPCClient(t *testing.T, address string, contractHash util.Uint160, accs ...*wallet.Account) (*client.Client, *rpcclient.Client) {
|
||||||
|
rpcCli, err := rpcclient.New(context.Background(), "http://"+address, rpcclient.Options{})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
var acc *wallet.Account
|
||||||
|
if len(accs) == 0 {
|
||||||
|
acc, err = wallet.NewAccount()
|
||||||
|
require.NoError(t, err)
|
||||||
|
} else {
|
||||||
|
require.Len(t, accs, 1)
|
||||||
|
acc = accs[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
cli, err := client.New(rpcCli, acc, contractHash, nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
return cli, rpcCli
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFrostFSID_Client_ContractOwnersManagement(t *testing.T) {
|
||||||
|
ffsid, cancel := initFrostfsIFClientTest(t)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
committeeInvoker := ffsid.base.CommitteeInvoker()
|
||||||
|
defaultOwnerAddress := ffsid.base.owner.ScriptHash()
|
||||||
|
_, newOwnerAddress := newKey(t)
|
||||||
|
|
||||||
|
checkAdminClient(t, ffsid.cli, defaultOwnerAddress)
|
||||||
|
|
||||||
|
_, _, err := ffsid.cli.SetAdmin(newOwnerAddress)
|
||||||
|
require.ErrorContains(t, err, "not witnessed")
|
||||||
|
committeeInvoker.Invoke(t, stackitem.Null{}, setAdminMethod, newOwnerAddress)
|
||||||
|
|
||||||
|
checkAdminClient(t, ffsid.cli, newOwnerAddress)
|
||||||
|
|
||||||
|
_, _, err = ffsid.cli.ClearAdmin()
|
||||||
|
require.ErrorContains(t, err, "not witnessed")
|
||||||
|
committeeInvoker.Invoke(t, stackitem.Null{}, clearAdminMethod)
|
||||||
|
|
||||||
|
checkAdminClient(t, ffsid.cli)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newKey(t *testing.T) (*keys.PrivateKey, util.Uint160) {
|
||||||
|
key, err := keys.NewPrivateKey()
|
||||||
|
require.NoError(t, err)
|
||||||
|
return key, key.PublicKey().GetScriptHash()
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkAdminClient(t *testing.T, cli *client.Client, owners ...util.Uint160) {
|
||||||
|
address, isSet, err := cli.GetAdmin()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, len(owners) > 0, isSet)
|
||||||
|
if isSet {
|
||||||
|
require.Equal(t, owners[0], address)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFrostFSID_Client_SubjectManagement(t *testing.T) {
|
||||||
|
ffsid, cancel := initFrostfsIFClientTest(t)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
subjKey, subjAddr := newKey(t)
|
||||||
|
extraKey, _ := newKey(t)
|
||||||
|
subjLogin := "subj-login"
|
||||||
|
iamPathKV := "iam/path"
|
||||||
|
|
||||||
|
ffsid.a.await(ffsid.cli.CreateSubject(subjKey.PublicKey()))
|
||||||
|
ffsid.a.await(ffsid.cli.SetSubjectName(subjAddr, subjLogin))
|
||||||
|
ffsid.a.await(ffsid.cli.SetSubjectKV(subjAddr, client.IAMPathKey, iamPathKV))
|
||||||
|
ffsid.a.await(ffsid.cli.AddSubjectKey(subjAddr, extraKey.PublicKey()))
|
||||||
|
|
||||||
|
subj, err := ffsid.cli.GetSubject(subjAddr)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.True(t, subjKey.PublicKey().Equal(subj.PrimaryKey))
|
||||||
|
require.Equal(t, subj.Name, subjLogin)
|
||||||
|
require.Equal(t, map[string]string{client.IAMPathKey: iamPathKV}, subj.KV)
|
||||||
|
require.ElementsMatch(t, []*keys.PublicKey{extraKey.PublicKey()}, subj.AdditionalKeys)
|
||||||
|
|
||||||
|
ffsid.a.await(ffsid.cli.DeleteSubjectKV(subjAddr, client.IAMPathKey))
|
||||||
|
subj, err = ffsid.cli.GetSubject(subjAddr)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Empty(t, subj.KV)
|
||||||
|
|
||||||
|
subjects, err := ffsid.cli.ListSubjects()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.ElementsMatch(t, subjects, []util.Uint160{subjAddr})
|
||||||
|
|
||||||
|
subj, err = ffsid.cli.GetSubjectByKey(extraKey.PublicKey())
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.True(t, subjKey.PublicKey().Equal(subj.PrimaryKey))
|
||||||
|
|
||||||
|
ffsid.a.await(ffsid.cli.RemoveSubjectKey(subjAddr, extraKey.PublicKey()))
|
||||||
|
_, err = ffsid.cli.GetSubjectByKey(extraKey.PublicKey())
|
||||||
|
require.ErrorContains(t, err, "not found")
|
||||||
|
|
||||||
|
ffsid.a.await(ffsid.cli.DeleteSubject(subjAddr))
|
||||||
|
|
||||||
|
_, err = ffsid.cli.GetSubject(subjAddr)
|
||||||
|
require.ErrorContains(t, err, "not found")
|
||||||
|
subjects, err = ffsid.cli.ListSubjects()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Empty(t, subjects)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFrostFSID_Client_NamespaceManagement(t *testing.T) {
|
||||||
|
ffsid, cancel := initFrostfsIFClientTest(t)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
subjKey, subjAddr := newKey(t)
|
||||||
|
ffsid.a.await(ffsid.cli.CreateSubject(subjKey.PublicKey()))
|
||||||
|
|
||||||
|
namespace := "namespace"
|
||||||
|
ffsid.a.await(ffsid.cli.CreateNamespace(namespace))
|
||||||
|
_, _, err := ffsid.cli.CreateNamespace(namespace)
|
||||||
|
require.ErrorContains(t, err, "already exists")
|
||||||
|
|
||||||
|
ns, err := ffsid.cli.GetNamespace(namespace)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, namespace, ns.Name)
|
||||||
|
|
||||||
|
namespaces, err := ffsid.cli.ListNamespaces()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.ElementsMatch(t, []*client.Namespace{ns}, namespaces)
|
||||||
|
|
||||||
|
ffsid.a.await(ffsid.cli.AddSubjectToNamespace(subjAddr, namespace))
|
||||||
|
_, _, err = ffsid.cli.AddSubjectToNamespace(subjAddr, namespace)
|
||||||
|
require.ErrorContains(t, err, "already added")
|
||||||
|
|
||||||
|
subj, err := ffsid.cli.GetSubject(subjAddr)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, namespace, subj.Namespace)
|
||||||
|
|
||||||
|
subjects, err := ffsid.cli.ListNamespaceSubjects(namespace)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.ElementsMatch(t, []util.Uint160{subjAddr}, subjects)
|
||||||
|
|
||||||
|
ffsid.a.await(ffsid.cli.RemoveSubjectFromNamespace(subjAddr))
|
||||||
|
|
||||||
|
subj, err = ffsid.cli.GetSubject(subjAddr)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Empty(t, subj.Namespace)
|
||||||
|
|
||||||
|
subjects, err = ffsid.cli.ListNamespaceSubjects(namespace)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Empty(t, subjects)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFrostFSID_Client_GroupManagement(t *testing.T) {
|
||||||
|
ffsid, cancel := initFrostfsIFClientTest(t)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
subjKey, subjAddr := newKey(t)
|
||||||
|
ffsid.a.await(ffsid.cli.CreateSubject(subjKey.PublicKey()))
|
||||||
|
|
||||||
|
namespace := "namespace"
|
||||||
|
ffsid.a.await(ffsid.cli.CreateNamespace(namespace))
|
||||||
|
|
||||||
|
groupName := "group"
|
||||||
|
groupID := int64(1)
|
||||||
|
actGroupID, err := ffsid.cli.ParseGroupID(ffsid.cli.Wait(ffsid.cli.CreateGroup(namespace, groupName)))
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, groupID, actGroupID)
|
||||||
|
|
||||||
|
_, _, err = ffsid.cli.CreateGroup(namespace, groupName)
|
||||||
|
require.ErrorContains(t, err, "is not available")
|
||||||
|
|
||||||
|
iamARN := "arn"
|
||||||
|
ffsid.a.await(ffsid.cli.SetGroupKV(namespace, groupID, client.IAMARNKey, iamARN))
|
||||||
|
|
||||||
|
group, err := ffsid.cli.GetGroup(namespace, groupID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, groupName, group.Name)
|
||||||
|
require.Equal(t, map[string]string{client.IAMARNKey: iamARN}, group.KV)
|
||||||
|
|
||||||
|
ffsid.a.await(ffsid.cli.DeleteGroupKV(namespace, groupID, client.IAMARNKey))
|
||||||
|
|
||||||
|
groupExt, err := ffsid.cli.GetGroupExtended(namespace, groupID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Zero(t, groupExt.SubjectsCount)
|
||||||
|
|
||||||
|
ffsid.a.await(ffsid.cli.AddSubjectToNamespace(subjAddr, namespace))
|
||||||
|
ffsid.a.await(ffsid.cli.AddSubjectToGroup(subjAddr, groupID))
|
||||||
|
|
||||||
|
subjExt, err := ffsid.cli.GetSubjectExtended(subjAddr)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.ElementsMatch(t, []*client.Group{{ID: groupID, Name: groupName, Namespace: namespace, KV: map[string]string{}}}, subjExt.Groups)
|
||||||
|
|
||||||
|
groupExt, err = ffsid.cli.GetGroupExtended(namespace, groupID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.EqualValues(t, 1, groupExt.SubjectsCount)
|
||||||
|
|
||||||
|
subjects, err := ffsid.cli.ListGroupSubjects(namespace, groupID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.ElementsMatch(t, []util.Uint160{subjAddr}, subjects)
|
||||||
|
|
||||||
|
ffsid.a.await(ffsid.cli.RemoveSubjectFromGroup(subjAddr, groupID))
|
||||||
|
|
||||||
|
subjects, err = ffsid.cli.ListGroupSubjects(namespace, groupID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Empty(t, subjects)
|
||||||
|
|
||||||
|
subjects, err = ffsid.cli.ListNamespaceSubjects(namespace)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.ElementsMatch(t, []util.Uint160{subjAddr}, subjects)
|
||||||
|
|
||||||
|
groups, err := ffsid.cli.ListGroups(namespace)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.ElementsMatch(t, []*client.Group{{ID: groupID, Name: groupName, Namespace: namespace, KV: map[string]string{}}}, groups)
|
||||||
|
|
||||||
|
ffsid.a.await(ffsid.cli.DeleteGroup(namespace, groupID))
|
||||||
|
_, err = ffsid.cli.GetGroup(namespace, groupID)
|
||||||
|
require.ErrorContains(t, err, "not found")
|
||||||
|
|
||||||
|
groups, err = ffsid.cli.ListGroups(namespace)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Empty(t, groups)
|
||||||
|
}
|
||||||
|
|
||||||
|
type testSubject struct {
|
||||||
|
key *keys.PrivateKey
|
||||||
|
addr util.Uint160
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFrostFSID_Client_Lists(t *testing.T) {
|
||||||
|
ffsid, cancel := initFrostfsIFClientTest(t)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
namespaces := []string{"empty-ns0", "ns1", "ns2", "ns3"}
|
||||||
|
|
||||||
|
tx := ffsid.cli.StartTx()
|
||||||
|
for _, namespace := range namespaces {
|
||||||
|
err := tx.WrapCall(ffsid.cli.CreateNamespaceCall(namespace))
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
ffsid.a.await(ffsid.cli.SendTx(tx))
|
||||||
|
|
||||||
|
subjects := make([]testSubject, 10)
|
||||||
|
tx = ffsid.cli.StartTx()
|
||||||
|
for i := range subjects {
|
||||||
|
subjects[i].key, subjects[i].addr = newKey(t)
|
||||||
|
err := tx.WrapCall(ffsid.cli.CreateSubjectCall(subjects[i].key.PublicKey()))
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
ffsid.a.await(ffsid.cli.SendTx(tx))
|
||||||
|
|
||||||
|
groups := []client.Group{
|
||||||
|
{
|
||||||
|
ID: 1,
|
||||||
|
Name: "empty-group0",
|
||||||
|
Namespace: namespaces[0],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ID: 2,
|
||||||
|
Name: "empty-group1",
|
||||||
|
Namespace: namespaces[1],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ID: 3,
|
||||||
|
Name: "group2",
|
||||||
|
Namespace: namespaces[1],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ID: 4,
|
||||||
|
Name: "group3",
|
||||||
|
Namespace: namespaces[2],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ID: 5,
|
||||||
|
Name: "group4",
|
||||||
|
Namespace: namespaces[3],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ID: 6,
|
||||||
|
Name: "group5",
|
||||||
|
Namespace: namespaces[3],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
tx = ffsid.cli.StartTx()
|
||||||
|
for _, group := range groups[:3] {
|
||||||
|
err := tx.WrapCall(ffsid.cli.CreateGroupCall(group.Namespace, group.Name))
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
ffsid.a.await(ffsid.cli.SendTx(tx))
|
||||||
|
|
||||||
|
// we split into two tx because of gas limit exceeded error
|
||||||
|
tx = ffsid.cli.StartTx()
|
||||||
|
for _, group := range groups[3:] {
|
||||||
|
err := tx.WrapCall(ffsid.cli.CreateGroupCall(group.Namespace, group.Name))
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
ffsid.a.await(ffsid.cli.SendTx(tx))
|
||||||
|
|
||||||
|
addSubjectsToNamespaces(t, ffsid, namespaces, subjects)
|
||||||
|
addSubjectsToGroups(t, ffsid, groups, subjects)
|
||||||
|
|
||||||
|
nsList, err := ffsid.cli.ListNamespaces()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.ElementsMatch(t, []*client.Namespace{{Name: namespaces[0]}, {Name: namespaces[1]}, {Name: namespaces[2]}, {Name: namespaces[3]}}, nsList)
|
||||||
|
|
||||||
|
nonEmptyNs, err := ffsid.cli.ListNonEmptyNamespaces()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.ElementsMatch(t, namespaces[1:], nonEmptyNs)
|
||||||
|
|
||||||
|
checkNamespaceSubjects(t, ffsid.cli, namespaces[0], subjects, 0, 0)
|
||||||
|
checkNamespaceSubjects(t, ffsid.cli, namespaces[1], subjects, 0, 3)
|
||||||
|
checkNamespaceSubjects(t, ffsid.cli, namespaces[2], subjects, 3, 5)
|
||||||
|
checkNamespaceSubjects(t, ffsid.cli, namespaces[3], subjects, 5, 10)
|
||||||
|
|
||||||
|
nonEmptyGroups, err := ffsid.cli.ListNonEmptyGroups(namespaces[1])
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.ElementsMatch(t, []string{groups[2].Name}, nonEmptyGroups)
|
||||||
|
|
||||||
|
checkGroupSubjects(t, ffsid.cli, groups[0], subjects, 0, 0)
|
||||||
|
checkGroupSubjects(t, ffsid.cli, groups[1], subjects, 0, 0)
|
||||||
|
checkGroupSubjects(t, ffsid.cli, groups[2], subjects, 2, 3)
|
||||||
|
checkGroupSubjects(t, ffsid.cli, groups[3], subjects, 3, 5)
|
||||||
|
checkGroupSubjects(t, ffsid.cli, groups[4], subjects, 6, 8)
|
||||||
|
checkGroupSubjects(t, ffsid.cli, groups[5], subjects, 8, 10)
|
||||||
|
}
|
||||||
|
|
||||||
|
func addSubjectsToNamespaces(t *testing.T, ffsid *testFrostFSIDClientInvoker, namespaces []string, subjects []testSubject) {
|
||||||
|
cli := ffsid.cli
|
||||||
|
|
||||||
|
tx := cli.StartTx()
|
||||||
|
for _, subject := range subjects[:3] {
|
||||||
|
err := tx.WrapCall(cli.AddSubjectToNamespaceCall(subject.addr, namespaces[1]))
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
ffsid.a.await(cli.SendTx(tx))
|
||||||
|
|
||||||
|
tx = cli.StartTx()
|
||||||
|
for _, subject := range subjects[3:5] {
|
||||||
|
err := tx.WrapCall(cli.AddSubjectToNamespaceCall(subject.addr, namespaces[2]))
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
ffsid.a.await(cli.SendTx(tx))
|
||||||
|
|
||||||
|
tx = cli.StartTx()
|
||||||
|
for _, subject := range subjects[5:] {
|
||||||
|
err := tx.WrapCall(cli.AddSubjectToNamespaceCall(subject.addr, namespaces[3]))
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
ffsid.a.await(cli.SendTx(tx))
|
||||||
|
}
|
||||||
|
|
||||||
|
func addSubjectsToGroups(t *testing.T, ffsid *testFrostFSIDClientInvoker, groups []client.Group, subjects []testSubject) {
|
||||||
|
cli := ffsid.cli
|
||||||
|
tx := cli.StartTx()
|
||||||
|
|
||||||
|
err := tx.WrapCall(cli.AddSubjectToGroupCall(subjects[2].addr, groups[2].ID))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
err = tx.WrapCall(cli.AddSubjectToGroupCall(subjects[3].addr, groups[3].ID))
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = tx.WrapCall(cli.AddSubjectToGroupCall(subjects[4].addr, groups[3].ID))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
ffsid.a.await(cli.SendTx(tx))
|
||||||
|
|
||||||
|
// we have to start new tx because of insufficient gas / gas limit exceeded error
|
||||||
|
tx = cli.StartTx()
|
||||||
|
|
||||||
|
err = tx.WrapCall(cli.AddSubjectToGroupCall(subjects[6].addr, groups[4].ID))
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = tx.WrapCall(cli.AddSubjectToGroupCall(subjects[7].addr, groups[4].ID))
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = tx.WrapCall(cli.AddSubjectToGroupCall(subjects[8].addr, groups[5].ID))
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = tx.WrapCall(cli.AddSubjectToGroupCall(subjects[9].addr, groups[5].ID))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
ffsid.a.await(cli.SendTx(tx))
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkNamespaceSubjects(t *testing.T, cli *client.Client, ns string, subjects []testSubject, start, end int) {
|
||||||
|
nsSubjects, err := cli.ListNamespaceSubjects(ns)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.ElementsMatch(t, subjSlice(subjects, start, end), nsSubjects)
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkGroupSubjects(t *testing.T, cli *client.Client, group client.Group, subjects []testSubject, start, end int) {
|
||||||
|
groupSubjects, err := cli.ListGroupSubjects(group.Namespace, group.ID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.ElementsMatch(t, subjSlice(subjects, start, end), groupSubjects)
|
||||||
|
}
|
||||||
|
|
||||||
|
func subjSlice(subjects []testSubject, start, end int) []util.Uint160 {
|
||||||
|
res := make([]util.Uint160, 0, end-start)
|
||||||
|
for i := start; i < end; i++ {
|
||||||
|
res = append(res, subjects[i].addr)
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFrostFSID_Client_UseCaseWithS3GW(t *testing.T) {
|
||||||
|
ffsid, cancel := initFrostfsIFClientTest(t)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
namespace := "namespace"
|
||||||
|
login := "login"
|
||||||
|
dataUserKey, dataUserAddr := newKey(t)
|
||||||
|
extraDataUserKey, _ := newKey(t)
|
||||||
|
|
||||||
|
// admin
|
||||||
|
tx := ffsid.cli.StartTx()
|
||||||
|
err := tx.WrapCall(ffsid.cli.CreateNamespaceCall(namespace))
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = tx.WrapCall(ffsid.cli.CreateSubjectCall(dataUserKey.PublicKey()))
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = tx.WrapCall(ffsid.cli.SetSubjectNameCall(dataUserAddr, login))
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = tx.WrapCall(ffsid.cli.AddSubjectKeyCall(dataUserAddr, extraDataUserKey.PublicKey()))
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = tx.WrapCall(ffsid.cli.AddSubjectToNamespaceCall(dataUserAddr, namespace))
|
||||||
|
require.NoError(t, err)
|
||||||
|
ffsid.a.await(ffsid.cli.SendTx(tx))
|
||||||
|
|
||||||
|
// s3-gw
|
||||||
|
subj, err := ffsid.cli.GetSubjectByKey(extraDataUserKey.PublicKey())
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, login, subj.Name)
|
||||||
|
require.True(t, dataUserKey.PublicKey().Equal(subj.PrimaryKey))
|
||||||
|
require.Equal(t, namespace, subj.Namespace)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFrostFSID_Client_UseCaseListNSSubjects(t *testing.T) {
|
||||||
|
ffsid, cancel := initFrostfsIFClientTest(t)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
namespace := "namespace"
|
||||||
|
group := "group"
|
||||||
|
groupID := int64(1)
|
||||||
|
|
||||||
|
tx := ffsid.cli.StartTx()
|
||||||
|
err := tx.WrapCall(ffsid.cli.CreateNamespaceCall(namespace))
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = tx.WrapCall(ffsid.cli.CreateGroupCall(namespace, group))
|
||||||
|
require.NoError(t, err)
|
||||||
|
ffsid.a.await(ffsid.cli.SendTx(tx))
|
||||||
|
|
||||||
|
// admin
|
||||||
|
|
||||||
|
subjects := make([]testSubject, 5)
|
||||||
|
|
||||||
|
for i := range subjects {
|
||||||
|
tx = ffsid.cli.StartTx()
|
||||||
|
subjects[i].key, subjects[i].addr = newKey(t)
|
||||||
|
err = tx.WrapCall(ffsid.cli.CreateSubjectCall(subjects[i].key.PublicKey()))
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = tx.WrapCall(ffsid.cli.SetSubjectNameCall(subjects[i].addr, "login"+strconv.Itoa(i)))
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = tx.WrapCall(ffsid.cli.AddSubjectToNamespaceCall(subjects[i].addr, namespace))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
if i > len(subjects)/2 {
|
||||||
|
err = tx.WrapCall(ffsid.cli.AddSubjectToGroupCall(subjects[i].addr, groupID))
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
ffsid.a.await(ffsid.cli.SendTx(tx))
|
||||||
|
}
|
||||||
|
|
||||||
|
nsSubjects, err := ffsid.cli.ListNamespaceSubjects(namespace)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
res := make([]*client.SubjectExtended, len(nsSubjects))
|
||||||
|
for i, subj := range nsSubjects {
|
||||||
|
res[i], err = ffsid.cli.GetSubjectExtended(subj)
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
prettyPrintExtendedSubjects(res)
|
||||||
|
}
|
||||||
|
|
||||||
|
func prettyPrintExtendedSubjects(subjects []*client.SubjectExtended) {
|
||||||
|
for _, subj := range subjects {
|
||||||
|
var sb strings.Builder
|
||||||
|
sb.WriteString(fmt.Sprintf("login: %s, namespace: %v, groups: [ ", subj.Name, subj.Namespace))
|
||||||
|
|
||||||
|
for _, group := range subj.Groups {
|
||||||
|
sb.WriteString(group.Namespace + ":" + group.Name + " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.WriteByte(']')
|
||||||
|
fmt.Println(sb.String())
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,111 +1,854 @@
|
||||||
package tests
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"errors"
|
||||||
"path"
|
"path"
|
||||||
"sort"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-contract/container"
|
"git.frostfs.info/TrueCloudLab/frostfs-contract/frostfsid/client"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/interop/storage"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/neotest"
|
"github.com/nspcc-dev/neo-go/pkg/neotest"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
const frostfsidPath = "../frostfsid"
|
const frostfsidPath = "../frostfsid"
|
||||||
|
|
||||||
func deployFrostFSIDContract(t *testing.T, e *neotest.Executor, addrNetmap, addrContainer util.Uint160) util.Uint160 {
|
const (
|
||||||
args := make([]interface{}, 5)
|
setAdminMethod = "setAdmin"
|
||||||
args[0] = false
|
getAdminMethod = "getAdmin"
|
||||||
args[1] = addrNetmap
|
clearAdminMethod = "clearAdmin"
|
||||||
args[2] = addrContainer
|
|
||||||
|
createSubjectMethod = "createSubject"
|
||||||
|
getSubjectMethod = "getSubject"
|
||||||
|
listSubjectsMethod = "listSubjects"
|
||||||
|
addSubjectKeyMethod = "addSubjectKey"
|
||||||
|
removeSubjectKeyMethod = "removeSubjectKey"
|
||||||
|
getSubjectByKeyMethod = "getSubjectByKey"
|
||||||
|
getSubjectKeyByNameMethod = "getSubjectKeyByName"
|
||||||
|
setSubjectNameMethod = "setSubjectName"
|
||||||
|
setSubjectKVMethod = "setSubjectKV"
|
||||||
|
deleteSubjectKVMethod = "deleteSubjectKV"
|
||||||
|
deleteSubjectMethod = "deleteSubject"
|
||||||
|
|
||||||
|
createNamespaceMethod = "createNamespace"
|
||||||
|
getNamespaceMethod = "getNamespace"
|
||||||
|
getNamespaceExtendedMethod = "getNamespaceExtended"
|
||||||
|
listNamespacesMethod = "listNamespaces"
|
||||||
|
addSubjectToNamespaceMethod = "addSubjectToNamespace"
|
||||||
|
removeSubjectFromNamespaceMethod = "removeSubjectFromNamespace"
|
||||||
|
listNamespaceSubjectsMethod = "listNamespaceSubjects"
|
||||||
|
|
||||||
|
createGroupMethod = "createGroup"
|
||||||
|
getGroupMethod = "getGroup"
|
||||||
|
getGroupExtendedMethod = "getGroupExtended"
|
||||||
|
getGroupIDByNameMethod = "getGroupIDByName"
|
||||||
|
setGroupNameMethod = "setGroupName"
|
||||||
|
setGroupKVMethod = "setGroupKV"
|
||||||
|
deleteGroupKVMethod = "deleteGroupKV"
|
||||||
|
listGroupsMethod = "listGroups"
|
||||||
|
addSubjectToGroupMethod = "addSubjectToGroup"
|
||||||
|
removeSubjectFromGroupMethod = "removeSubjectFromGroup"
|
||||||
|
listGroupSubjectsMethod = "listGroupSubjects"
|
||||||
|
deleteGroupMethod = "deleteGroup"
|
||||||
|
)
|
||||||
|
|
||||||
|
const notWitnessedError = "not witnessed"
|
||||||
|
|
||||||
|
type testFrostFSIDInvoker struct {
|
||||||
|
e *neotest.Executor
|
||||||
|
contractHash util.Uint160
|
||||||
|
owner *wallet.Account
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *testFrostFSIDInvoker) OwnerInvoker() *neotest.ContractInvoker {
|
||||||
|
return f.e.NewInvoker(f.contractHash, neotest.NewSingleSigner(f.owner))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *testFrostFSIDInvoker) CommitteeInvoker() *neotest.ContractInvoker {
|
||||||
|
return f.e.CommitteeInvoker(f.contractHash)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *testFrostFSIDInvoker) AnonInvoker(t *testing.T) *neotest.ContractInvoker {
|
||||||
|
acc, err := wallet.NewAccount()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
return f.e.NewInvoker(f.contractHash, newSigner(t, f.CommitteeInvoker(), acc))
|
||||||
|
}
|
||||||
|
|
||||||
|
func newSigner(t *testing.T, c *neotest.ContractInvoker, acc *wallet.Account) neotest.Signer {
|
||||||
|
amount := int64(100_0000_0000)
|
||||||
|
|
||||||
|
tx := c.NewTx(t, []neotest.Signer{c.Validator},
|
||||||
|
c.NativeHash(t, nativenames.Gas), "transfer",
|
||||||
|
c.Validator.ScriptHash(), acc.Contract.ScriptHash(), amount, nil)
|
||||||
|
c.AddNewBlock(t, tx)
|
||||||
|
c.CheckHalt(t, tx.Hash())
|
||||||
|
return neotest.NewSingleSigner(acc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func deployFrostFSIDContract(t *testing.T, e *neotest.Executor, contractOwner util.Uint160) util.Uint160 {
|
||||||
|
args := make([]any, 5)
|
||||||
|
args[0] = contractOwner
|
||||||
|
|
||||||
c := neotest.CompileFile(t, e.CommitteeHash, frostfsidPath, path.Join(frostfsidPath, "config.yml"))
|
c := neotest.CompileFile(t, e.CommitteeHash, frostfsidPath, path.Join(frostfsidPath, "config.yml"))
|
||||||
e.DeployContract(t, c, args)
|
e.DeployContract(t, c, args)
|
||||||
return c.Hash
|
return c.Hash
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFrostFSIDInvoker(t *testing.T) *neotest.ContractInvoker {
|
func newFrostFSIDInvoker(t *testing.T) *testFrostFSIDInvoker {
|
||||||
e := newExecutor(t)
|
e := newExecutor(t)
|
||||||
|
|
||||||
ctrNNS := neotest.CompileFile(t, e.CommitteeHash, nnsPath, path.Join(nnsPath, "config.yml"))
|
acc, err := wallet.NewAccount()
|
||||||
ctrNetmap := neotest.CompileFile(t, e.CommitteeHash, netmapPath, path.Join(netmapPath, "config.yml"))
|
require.NoError(t, err)
|
||||||
ctrBalance := neotest.CompileFile(t, e.CommitteeHash, balancePath, path.Join(balancePath, "config.yml"))
|
|
||||||
ctrContainer := neotest.CompileFile(t, e.CommitteeHash, containerPath, path.Join(containerPath, "config.yml"))
|
|
||||||
|
|
||||||
e.DeployContract(t, ctrNNS, nil)
|
h := deployFrostFSIDContract(t, e, acc.ScriptHash())
|
||||||
deployNetmapContract(t, e, ctrBalance.Hash, ctrContainer.Hash,
|
|
||||||
container.RegistrationFeeKey, int64(containerFee),
|
newSigner(t, e.CommitteeInvoker(h), acc)
|
||||||
container.AliasFeeKey, int64(containerAliasFee))
|
|
||||||
deployBalanceContract(t, e, ctrNetmap.Hash, ctrContainer.Hash)
|
return &testFrostFSIDInvoker{
|
||||||
deployContainerContract(t, e, ctrNetmap.Hash, ctrBalance.Hash, ctrNNS.Hash)
|
e: e,
|
||||||
h := deployFrostFSIDContract(t, e, ctrNetmap.Hash, ctrContainer.Hash)
|
contractHash: h,
|
||||||
return e.CommitteeInvoker(h)
|
owner: acc,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFrostFSID_AddKey(t *testing.T) {
|
func TestFrostFSID_ContractOwnersManagement(t *testing.T) {
|
||||||
e := newFrostFSIDInvoker(t)
|
f := newFrostFSIDInvoker(t)
|
||||||
|
|
||||||
pubs := make([][]byte, 6)
|
anonInvoker := f.AnonInvoker(t)
|
||||||
for i := range pubs {
|
anonInvokerHash := anonInvoker.Signers[0].ScriptHash()
|
||||||
p, err := keys.NewPrivateKey()
|
invoker := f.OwnerInvoker()
|
||||||
|
invokerHash := invoker.Signers[0].ScriptHash()
|
||||||
|
committeeInvoker := f.CommitteeInvoker()
|
||||||
|
|
||||||
|
checkOwner(t, anonInvoker, invokerHash)
|
||||||
|
|
||||||
|
anonInvoker.InvokeFail(t, notWitnessedError, createNamespaceMethod, "namespace")
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, createNamespaceMethod, "namespace")
|
||||||
|
|
||||||
|
t.Run("setAdmin is only allowed for committee", func(t *testing.T) {
|
||||||
|
invoker.InvokeFail(t, notWitnessedError, setAdminMethod, anonInvokerHash)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("replace owner", func(t *testing.T) {
|
||||||
|
committeeInvoker.Invoke(t, stackitem.Null{}, setAdminMethod, anonInvokerHash)
|
||||||
|
checkOwner(t, anonInvoker, anonInvokerHash)
|
||||||
|
|
||||||
|
invoker.InvokeFail(t, notWitnessedError, createNamespaceMethod, "namespace2")
|
||||||
|
anonInvoker.Invoke(t, stackitem.Null{}, createNamespaceMethod, "namespace2")
|
||||||
|
})
|
||||||
|
t.Run("remove owner", func(t *testing.T) {
|
||||||
|
committeeInvoker.Invoke(t, stackitem.Null{}, clearAdminMethod)
|
||||||
|
checkOwner(t, anonInvoker)
|
||||||
|
|
||||||
|
invoker.InvokeFail(t, notWitnessedError, createNamespaceMethod, "namespace3")
|
||||||
|
anonInvoker.InvokeFail(t, notWitnessedError, createNamespaceMethod, "namespace3")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkOwner(t *testing.T, invoker *neotest.ContractInvoker, owner ...util.Uint160) {
|
||||||
|
if len(owner) > 1 {
|
||||||
|
require.Fail(t, "invalid testcase")
|
||||||
|
}
|
||||||
|
|
||||||
|
s, err := invoker.TestInvoke(t, getAdminMethod)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, 1, s.Len(), "unexpected number items on stack")
|
||||||
|
if len(owner) == 0 {
|
||||||
|
_, isMissing := s.Pop().Item().(stackitem.Null)
|
||||||
|
require.True(t, isMissing)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
bs, err := s.Pop().Item().TryBytes()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, bs, owner[0].BytesBE())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFrostFSID_SubjectManagement(t *testing.T) {
|
||||||
|
f := newFrostFSIDInvoker(t)
|
||||||
|
|
||||||
|
subjKey, err := keys.NewPrivateKey()
|
||||||
|
require.NoError(t, err)
|
||||||
|
subjKeyAddr := subjKey.PublicKey().GetScriptHash()
|
||||||
|
|
||||||
|
anonInvoker := f.AnonInvoker(t)
|
||||||
|
invoker := f.OwnerInvoker()
|
||||||
|
|
||||||
|
anonInvoker.InvokeFail(t, notWitnessedError, createSubjectMethod, subjKey.PublicKey().Bytes())
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, createSubjectMethod, subjKey.PublicKey().Bytes())
|
||||||
|
invoker.InvokeFail(t, "already exists", createSubjectMethod, subjKey.PublicKey().Bytes())
|
||||||
|
|
||||||
|
s, err := anonInvoker.TestInvoke(t, getSubjectMethod, subjKeyAddr)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
subj := parseSubject(t, s)
|
||||||
|
require.True(t, subjKey.PublicKey().Equal(&subj.PrimaryKey))
|
||||||
|
|
||||||
|
t.Run("add subject key", func(t *testing.T) {
|
||||||
|
subjNewKey, err := keys.NewPrivateKey()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
pubs[i] = p.PublicKey().Bytes()
|
|
||||||
}
|
|
||||||
acc := e.NewAccount(t)
|
|
||||||
owner := signerToOwner(acc)
|
|
||||||
e.Invoke(t, stackitem.Null{}, "addKey", owner,
|
|
||||||
[]interface{}{pubs[0], pubs[1]})
|
|
||||||
|
|
||||||
sort.Slice(pubs[:2], func(i, j int) bool {
|
anonInvoker.InvokeFail(t, notWitnessedError, addSubjectKeyMethod, subjKeyAddr, subjNewKey.PublicKey().Bytes())
|
||||||
return bytes.Compare(pubs[i], pubs[j]) == -1
|
invoker.Invoke(t, stackitem.Null{}, addSubjectKeyMethod, subjKeyAddr, subjNewKey.PublicKey().Bytes())
|
||||||
})
|
|
||||||
arr := []stackitem.Item{
|
|
||||||
stackitem.NewBuffer(pubs[0]),
|
|
||||||
stackitem.NewBuffer(pubs[1]),
|
|
||||||
}
|
|
||||||
e.Invoke(t, stackitem.NewArray(arr), "key", owner)
|
|
||||||
|
|
||||||
t.Run("multiple addKey per block", func(t *testing.T) {
|
s, err = anonInvoker.TestInvoke(t, getSubjectMethod, subjKeyAddr)
|
||||||
tx1 := e.PrepareInvoke(t, "addKey", owner, []interface{}{pubs[2]})
|
require.NoError(t, err)
|
||||||
tx2 := e.PrepareInvoke(t, "addKey", owner, []interface{}{pubs[3], pubs[4]})
|
subj := parseSubject(t, s)
|
||||||
e.AddNewBlock(t, tx1, tx2)
|
require.Len(t, subj.AdditionalKeys, 1)
|
||||||
e.CheckHalt(t, tx1.Hash(), stackitem.Null{})
|
require.True(t, subjNewKey.PublicKey().Equal(subj.AdditionalKeys[0]))
|
||||||
e.CheckHalt(t, tx2.Hash(), stackitem.Null{})
|
|
||||||
|
|
||||||
sort.Slice(pubs[:5], func(i, j int) bool {
|
t.Run("get subject by additional key", func(t *testing.T) {
|
||||||
return bytes.Compare(pubs[i], pubs[j]) == -1
|
s, err = anonInvoker.TestInvoke(t, getSubjectByKeyMethod, subjNewKey.PublicKey().Bytes())
|
||||||
|
require.NoError(t, err)
|
||||||
|
subj := parseSubject(t, s)
|
||||||
|
require.True(t, subjKey.PublicKey().Equal(&subj.PrimaryKey), "keys must be the same")
|
||||||
|
|
||||||
|
s, err = anonInvoker.TestInvoke(t, getSubjectByKeyMethod, subjKey.PublicKey().Bytes())
|
||||||
|
require.NoError(t, err)
|
||||||
|
subj = parseSubject(t, s)
|
||||||
|
require.True(t, subjKey.PublicKey().Equal(&subj.PrimaryKey), "keys must be the same")
|
||||||
|
|
||||||
|
t.Run("remove subject key", func(t *testing.T) {
|
||||||
|
anonInvoker.InvokeFail(t, notWitnessedError, removeSubjectKeyMethod, subjKeyAddr, subjNewKey.PublicKey().Bytes())
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, removeSubjectKeyMethod, subjKeyAddr, subjNewKey.PublicKey().Bytes())
|
||||||
|
|
||||||
|
anonInvoker.InvokeFail(t, "not found", getSubjectByKeyMethod, subjNewKey.PublicKey().Bytes())
|
||||||
|
})
|
||||||
})
|
})
|
||||||
arr = []stackitem.Item{
|
|
||||||
stackitem.NewBuffer(pubs[0]),
|
|
||||||
stackitem.NewBuffer(pubs[1]),
|
|
||||||
stackitem.NewBuffer(pubs[2]),
|
|
||||||
stackitem.NewBuffer(pubs[3]),
|
|
||||||
stackitem.NewBuffer(pubs[4]),
|
|
||||||
}
|
|
||||||
e.Invoke(t, stackitem.NewArray(arr), "key", owner)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
e.Invoke(t, stackitem.Null{}, "removeKey", owner,
|
t.Run("set subject name", func(t *testing.T) {
|
||||||
[]interface{}{pubs[1], pubs[5]})
|
login := "some-login"
|
||||||
arr = []stackitem.Item{
|
|
||||||
stackitem.NewBuffer(pubs[0]),
|
|
||||||
stackitem.NewBuffer(pubs[2]),
|
|
||||||
stackitem.NewBuffer(pubs[3]),
|
|
||||||
stackitem.NewBuffer(pubs[4]),
|
|
||||||
}
|
|
||||||
e.Invoke(t, stackitem.NewArray(arr), "key", owner)
|
|
||||||
|
|
||||||
t.Run("multiple removeKey per block", func(t *testing.T) {
|
anonInvoker.InvokeFail(t, notWitnessedError, setSubjectNameMethod, subjKeyAddr, login)
|
||||||
tx1 := e.PrepareInvoke(t, "removeKey", owner, []interface{}{pubs[2]})
|
invoker.Invoke(t, stackitem.Null{}, setSubjectNameMethod, subjKeyAddr, login)
|
||||||
tx2 := e.PrepareInvoke(t, "removeKey", owner, []interface{}{pubs[0], pubs[4]})
|
|
||||||
e.AddNewBlock(t, tx1, tx2)
|
|
||||||
e.CheckHalt(t, tx1.Hash(), stackitem.Null{})
|
|
||||||
e.CheckHalt(t, tx2.Hash(), stackitem.Null{})
|
|
||||||
|
|
||||||
arr = []stackitem.Item{stackitem.NewBuffer(pubs[3])}
|
s, err = anonInvoker.TestInvoke(t, getSubjectMethod, subjKeyAddr)
|
||||||
e.Invoke(t, stackitem.NewArray(arr), "key", owner)
|
require.NoError(t, err)
|
||||||
|
subj = parseSubject(t, s)
|
||||||
|
require.Equal(t, login, subj.Name)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("set subject KVs", func(t *testing.T) {
|
||||||
|
iamPath := "iam/path"
|
||||||
|
|
||||||
|
anonInvoker.InvokeFail(t, notWitnessedError, setSubjectKVMethod, subjKeyAddr, client.IAMPathKey, iamPath)
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, setSubjectKVMethod, subjKeyAddr, client.IAMPathKey, iamPath)
|
||||||
|
|
||||||
|
s, err = anonInvoker.TestInvoke(t, getSubjectMethod, subjKeyAddr)
|
||||||
|
require.NoError(t, err)
|
||||||
|
subj = parseSubject(t, s)
|
||||||
|
require.Equal(t, iamPath, subj.KV[client.IAMPathKey])
|
||||||
|
|
||||||
|
anonInvoker.InvokeFail(t, notWitnessedError, deleteSubjectKVMethod, subjKeyAddr, client.IAMPathKey)
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, deleteSubjectKVMethod, subjKeyAddr, client.IAMPathKey)
|
||||||
|
|
||||||
|
s, err = anonInvoker.TestInvoke(t, getSubjectMethod, subjKeyAddr)
|
||||||
|
require.NoError(t, err)
|
||||||
|
subj = parseSubject(t, s)
|
||||||
|
require.Empty(t, subj.KV)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("list subjects", func(t *testing.T) {
|
||||||
|
newSubjKey, err := keys.NewPrivateKey()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, createSubjectMethod, newSubjKey.PublicKey().Bytes())
|
||||||
|
|
||||||
|
s, err = anonInvoker.TestInvoke(t, listSubjectsMethod)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
addresses, err := unwrap.ArrayOfUint160(makeValidRes(stackitem.NewArray(readIteratorAll(s))), nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Len(t, addresses, 2)
|
||||||
|
require.ElementsMatch(t, addresses, []util.Uint160{subjKeyAddr, newSubjKey.PublicKey().GetScriptHash()})
|
||||||
|
})
|
||||||
|
|
||||||
|
anonInvoker.InvokeFail(t, notWitnessedError, deleteSubjectMethod, subjKeyAddr)
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, deleteSubjectMethod, subjKeyAddr)
|
||||||
|
|
||||||
|
anonInvoker.InvokeFail(t, "subject not found", getSubjectMethod, subjKeyAddr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFrostFSIS_SubjectNameRelatedInvariants(t *testing.T) {
|
||||||
|
f := newFrostFSIDInvoker(t)
|
||||||
|
|
||||||
|
subjName1 := "subj1"
|
||||||
|
subjKey1, err := keys.NewPrivateKey()
|
||||||
|
require.NoError(t, err)
|
||||||
|
subjKeyAddr1 := subjKey1.PublicKey().GetScriptHash()
|
||||||
|
|
||||||
|
subjName2 := "subj2"
|
||||||
|
subjKey2, err := keys.NewPrivateKey()
|
||||||
|
require.NoError(t, err)
|
||||||
|
subjKeyAddr2 := subjKey2.PublicKey().GetScriptHash()
|
||||||
|
|
||||||
|
invoker := f.OwnerInvoker()
|
||||||
|
|
||||||
|
ns1, ns2 := "ns1", "ns2"
|
||||||
|
|
||||||
|
// Create two subject (one of them with name)
|
||||||
|
// Create two namespace.
|
||||||
|
// Add these subjects to ns1
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, createSubjectMethod, subjKey1.PublicKey().Bytes())
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, setSubjectNameMethod, subjKeyAddr1, subjName1)
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, createSubjectMethod, subjKey2.PublicKey().Bytes())
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, createNamespaceMethod, ns1)
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, createNamespaceMethod, ns2)
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, addSubjectToNamespaceMethod, subjKeyAddr1, ns1)
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, addSubjectToNamespaceMethod, subjKeyAddr2, ns1)
|
||||||
|
|
||||||
|
// Check that we can find public key by name for subj1 (with name)
|
||||||
|
// and cannot find key for subj2 (without name)
|
||||||
|
s, err := invoker.TestInvoke(t, getSubjectKeyByNameMethod, ns1, subjName1)
|
||||||
|
checkPublicKeyResult(t, s, err, subjKey1)
|
||||||
|
s, err = invoker.TestInvoke(t, getSubjectKeyByNameMethod, ns1, subjName2)
|
||||||
|
checkPublicKeyResult(t, s, err, nil)
|
||||||
|
|
||||||
|
// Check that we can find public key for by name for subj2 when we set its name
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, setSubjectNameMethod, subjKeyAddr2, subjName2)
|
||||||
|
s, err = invoker.TestInvoke(t, getSubjectKeyByNameMethod, ns1, subjName2)
|
||||||
|
checkPublicKeyResult(t, s, err, subjKey2)
|
||||||
|
|
||||||
|
// Check that we cannot set for second subject name that the first subject has already taken
|
||||||
|
invoker.InvokeFail(t, "not available", setSubjectNameMethod, subjKeyAddr2, subjName1)
|
||||||
|
|
||||||
|
// Check that we cannot move subject from one namespace to another
|
||||||
|
invoker.InvokeFail(t, "cannot be moved", addSubjectToNamespaceMethod, subjKeyAddr2, ns2)
|
||||||
|
|
||||||
|
// Check that we cannot find public key by name for subject that was removed from namespace
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, removeSubjectFromNamespaceMethod, subjKeyAddr2)
|
||||||
|
s, err = invoker.TestInvoke(t, getSubjectKeyByNameMethod, ns1, subjName2)
|
||||||
|
checkPublicKeyResult(t, s, err, nil)
|
||||||
|
|
||||||
|
// Check that we can find public key by name for subject in new namespace
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, addSubjectToNamespaceMethod, subjKeyAddr2, ns2)
|
||||||
|
s, err = invoker.TestInvoke(t, getSubjectKeyByNameMethod, ns2, subjName2)
|
||||||
|
checkPublicKeyResult(t, s, err, subjKey2)
|
||||||
|
|
||||||
|
// Check that subj2 can have the same name as subj1 if they belong to different namespaces
|
||||||
|
// Also check that after subject renaming its key cannot be found by old name
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, setSubjectNameMethod, subjKeyAddr2, subjName1)
|
||||||
|
s, err = invoker.TestInvoke(t, getSubjectKeyByNameMethod, ns2, subjName1)
|
||||||
|
checkPublicKeyResult(t, s, err, subjKey2)
|
||||||
|
s, err = invoker.TestInvoke(t, getSubjectKeyByNameMethod, ns2, subjName2)
|
||||||
|
checkPublicKeyResult(t, s, err, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFrostFSIS_GroupNameRelatedInvariants(t *testing.T) {
|
||||||
|
f := newFrostFSIDInvoker(t)
|
||||||
|
|
||||||
|
groupName1, groupName2 := "group1", "group2"
|
||||||
|
groupID1, groupID2 := int64(1), int64(2)
|
||||||
|
|
||||||
|
invoker := f.OwnerInvoker()
|
||||||
|
|
||||||
|
ns1, ns2 := "ns1", "ns2"
|
||||||
|
|
||||||
|
// Create two group
|
||||||
|
// Create two namespace.
|
||||||
|
// Add these groups to ns1
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, createNamespaceMethod, ns1)
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, createNamespaceMethod, ns2)
|
||||||
|
invoker.Invoke(t, stackitem.Make(groupID1), createGroupMethod, ns1, groupName1)
|
||||||
|
invoker.Invoke(t, stackitem.Make(groupID2), createGroupMethod, ns1, groupName2)
|
||||||
|
|
||||||
|
// Check that we can find group id by name for group1 in ns1 and not in ns2
|
||||||
|
s, err := invoker.TestInvoke(t, getGroupIDByNameMethod, ns1, groupName1)
|
||||||
|
checkGroupIDResult(t, s, err, groupID1)
|
||||||
|
s, err = invoker.TestInvoke(t, getGroupIDByNameMethod, ns2, groupName1)
|
||||||
|
checkGroupIDResult(t, s, err, -1)
|
||||||
|
|
||||||
|
// Check that we cannot set for second group name that the first subject has already taken
|
||||||
|
invoker.InvokeFail(t, "not available", setGroupNameMethod, ns1, groupID1, groupName2)
|
||||||
|
|
||||||
|
// Check that we cannot create group with the same name in namespace, but can in another
|
||||||
|
invoker.InvokeFail(t, "not available", createGroupMethod, ns1, groupName2)
|
||||||
|
invoker.Invoke(t, stackitem.Make(3), createGroupMethod, ns2, groupName2)
|
||||||
|
|
||||||
|
// Check that we cannot find group id by name for group that was removed
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, deleteGroupMethod, ns1, groupID2)
|
||||||
|
s, err = invoker.TestInvoke(t, getGroupIDByNameMethod, ns1, groupName2)
|
||||||
|
checkGroupIDResult(t, s, err, -1)
|
||||||
|
|
||||||
|
// Check that we can create group with the name that was freed after deleting
|
||||||
|
invoker.Invoke(t, stackitem.Make(4), createGroupMethod, ns1, groupName2)
|
||||||
|
|
||||||
|
// Check that after group renaming its id cannot be found by old name
|
||||||
|
newGroupName := "new"
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, setGroupNameMethod, ns1, groupID1, newGroupName)
|
||||||
|
s, err = invoker.TestInvoke(t, getGroupIDByNameMethod, ns1, groupName1)
|
||||||
|
checkGroupIDResult(t, s, err, -1)
|
||||||
|
s, err = invoker.TestInvoke(t, getGroupIDByNameMethod, ns1, newGroupName)
|
||||||
|
checkGroupIDResult(t, s, err, groupID1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFrostFSID_NamespaceManagement(t *testing.T) {
|
||||||
|
f := newFrostFSIDInvoker(t)
|
||||||
|
|
||||||
|
anonInvoker := f.AnonInvoker(t)
|
||||||
|
invoker := f.OwnerInvoker()
|
||||||
|
|
||||||
|
namespace := "some-namespace"
|
||||||
|
|
||||||
|
anonInvoker.InvokeFail(t, notWitnessedError, createNamespaceMethod, namespace)
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, createNamespaceMethod, namespace)
|
||||||
|
invoker.InvokeFail(t, "already exists", createNamespaceMethod, namespace)
|
||||||
|
|
||||||
|
s, err := anonInvoker.TestInvoke(t, getNamespaceMethod, namespace)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
ns := parseNamespace(t, s.Pop().Item())
|
||||||
|
require.Equal(t, namespace, ns.Name)
|
||||||
|
|
||||||
|
t.Run("add user to namespace", func(t *testing.T) {
|
||||||
|
subjKey, err := keys.NewPrivateKey()
|
||||||
|
require.NoError(t, err)
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, createSubjectMethod, subjKey.PublicKey().Bytes())
|
||||||
|
|
||||||
|
subjName := "name"
|
||||||
|
subjAddress := subjKey.PublicKey().GetScriptHash()
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, setSubjectNameMethod, subjAddress, subjName)
|
||||||
|
|
||||||
|
anonInvoker.InvokeFail(t, notWitnessedError, addSubjectToNamespaceMethod, subjAddress, namespace)
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, addSubjectToNamespaceMethod, subjAddress, namespace)
|
||||||
|
invoker.InvokeFail(t, "already added", addSubjectToNamespaceMethod, subjAddress, namespace)
|
||||||
|
|
||||||
|
s, err := anonInvoker.TestInvoke(t, getSubjectMethod, subjAddress)
|
||||||
|
require.NoError(t, err)
|
||||||
|
subj := parseSubject(t, s)
|
||||||
|
require.Equal(t, namespace, subj.Namespace)
|
||||||
|
|
||||||
|
t.Run("list namespace subjects", func(t *testing.T) {
|
||||||
|
s, err := anonInvoker.TestInvoke(t, listNamespaceSubjectsMethod, namespace)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
addresses, err := unwrap.ArrayOfUint160(makeValidRes(stackitem.NewArray(readIteratorAll(s))), nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.ElementsMatch(t, addresses, []util.Uint160{subjAddress})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("get subject key by name", func(t *testing.T) {
|
||||||
|
s, err := anonInvoker.TestInvoke(t, getSubjectKeyByNameMethod, namespace, subjName)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
foundKey, err := unwrap.PublicKey(makeValidRes(s.Pop().Item()), nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, subjKey.PublicKey(), foundKey)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("list namespaces", func(t *testing.T) {
|
||||||
|
namespace2 := "some-namespace2"
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, createNamespaceMethod, namespace2)
|
||||||
|
|
||||||
|
s, err := anonInvoker.TestInvoke(t, listNamespacesMethod)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
namespaces := parseNamespaces(t, readIteratorAll(s))
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.ElementsMatch(t, namespaces, []Namespace{{Name: namespace}, {Name: namespace2}})
|
||||||
|
|
||||||
|
t.Run("find namespaces with some subjects", func(t *testing.T) {
|
||||||
|
for _, ns := range namespaces {
|
||||||
|
s, err := anonInvoker.TestInvoke(t, getNamespaceExtendedMethod, ns.Name)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
nsExt := parseNamespaceExtended(t, s.Pop().Item())
|
||||||
|
if nsExt.SubjectsCount > 0 {
|
||||||
|
require.Equal(t, namespace, nsExt.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run("remove subject from namespace", func(t *testing.T) {
|
||||||
|
anonInvoker.InvokeFail(t, notWitnessedError, removeSubjectFromNamespaceMethod, subjAddress)
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, removeSubjectFromNamespaceMethod, subjAddress)
|
||||||
|
|
||||||
|
s, err := anonInvoker.TestInvoke(t, getSubjectMethod, subjAddress)
|
||||||
|
require.NoError(t, err)
|
||||||
|
subj := parseSubject(t, s)
|
||||||
|
require.Empty(t, subj.Namespace)
|
||||||
|
|
||||||
|
s, err = anonInvoker.TestInvoke(t, getNamespaceExtendedMethod, namespace)
|
||||||
|
require.NoError(t, err)
|
||||||
|
nsExt := parseNamespaceExtended(t, s.Pop().Item())
|
||||||
|
require.Zero(t, nsExt.SubjectsCount)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFrostFSID_GroupManagement(t *testing.T) {
|
||||||
|
f := newFrostFSIDInvoker(t)
|
||||||
|
|
||||||
|
anonInvoker := f.AnonInvoker(t)
|
||||||
|
invoker := f.OwnerInvoker()
|
||||||
|
|
||||||
|
nsName := "namespace"
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, createNamespaceMethod, nsName)
|
||||||
|
|
||||||
|
groupID := int64(1)
|
||||||
|
groupName := "group"
|
||||||
|
anonInvoker.InvokeFail(t, notWitnessedError, createGroupMethod, nsName, groupName)
|
||||||
|
invoker.Invoke(t, stackitem.Make(groupID), createGroupMethod, nsName, groupName)
|
||||||
|
|
||||||
|
s, err := anonInvoker.TestInvoke(t, getGroupMethod, nsName, groupID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
group := parseGroup(t, s.Pop().Item())
|
||||||
|
require.Equal(t, groupID, group.ID)
|
||||||
|
require.Equal(t, groupName, group.Name)
|
||||||
|
|
||||||
|
s, err = anonInvoker.TestInvoke(t, listGroupsMethod, nsName)
|
||||||
|
require.NoError(t, err)
|
||||||
|
groups := parseGroups(t, readIteratorAll(s))
|
||||||
|
require.ElementsMatch(t, groups, []Group{{ID: groupID, Name: groupName, Namespace: nsName}})
|
||||||
|
|
||||||
|
t.Run("add subjects to group", func(t *testing.T) {
|
||||||
|
subjKey, err := keys.NewPrivateKey()
|
||||||
|
require.NoError(t, err)
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, createSubjectMethod, subjKey.PublicKey().Bytes())
|
||||||
|
|
||||||
|
subjAddress := subjKey.PublicKey().GetScriptHash()
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, addSubjectToNamespaceMethod, subjAddress, nsName)
|
||||||
|
anonInvoker.InvokeFail(t, "not witnessed", addSubjectToGroupMethod, subjAddress, groupID)
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, addSubjectToGroupMethod, subjAddress, groupID)
|
||||||
|
|
||||||
|
t.Run("list group subjects", func(t *testing.T) {
|
||||||
|
s, err = anonInvoker.TestInvoke(t, listGroupSubjectsMethod, nsName, groupID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
addresses, err := unwrap.ArrayOfUint160(makeValidRes(stackitem.NewArray(readIteratorAll(s))), nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.ElementsMatch(t, addresses, []util.Uint160{subjAddress})
|
||||||
|
|
||||||
|
anonInvoker.InvokeFail(t, "not witnessed", removeSubjectFromGroupMethod, subjAddress, groupID)
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, removeSubjectFromGroupMethod, subjAddress, groupID)
|
||||||
|
|
||||||
|
s, err = anonInvoker.TestInvoke(t, listGroupSubjectsMethod, nsName, groupID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
addresses, err = unwrap.ArrayOfUint160(makeValidRes(stackitem.NewArray(readIteratorAll(s))), nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Empty(t, addresses)
|
||||||
|
|
||||||
|
t.Run("get group extended", func(t *testing.T) {
|
||||||
|
subjectsCount := 10
|
||||||
|
for i := 0; i < subjectsCount; i++ {
|
||||||
|
subjKey, err := keys.NewPrivateKey()
|
||||||
|
require.NoError(t, err)
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, createSubjectMethod, subjKey.PublicKey().Bytes())
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, addSubjectToNamespaceMethod, subjKey.PublicKey().GetScriptHash(), nsName)
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, addSubjectToGroupMethod, subjKey.PublicKey().GetScriptHash(), groupID)
|
||||||
|
}
|
||||||
|
|
||||||
|
s, err = anonInvoker.TestInvoke(t, getGroupExtendedMethod, nsName, groupID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
groupExt := parseGroupExtended(t, s.Pop().Item())
|
||||||
|
require.Equal(t, groupID, groupExt.ID)
|
||||||
|
require.Equal(t, groupName, groupExt.Name)
|
||||||
|
require.Empty(t, groupExt.KV)
|
||||||
|
require.EqualValues(t, subjectsCount, groupExt.SubjectsCount)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("set group name", func(t *testing.T) {
|
||||||
|
newGroupName := "new-name"
|
||||||
|
|
||||||
|
anonInvoker.InvokeFail(t, notWitnessedError, setGroupNameMethod, nsName, groupID, newGroupName)
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, setGroupNameMethod, nsName, groupID, newGroupName)
|
||||||
|
|
||||||
|
s, err = anonInvoker.TestInvoke(t, getGroupIDByNameMethod, nsName, newGroupName)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, groupID, s.Pop().BigInt().Int64())
|
||||||
|
|
||||||
|
s, err = anonInvoker.TestInvoke(t, getGroupMethod, nsName, groupID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
group = parseGroup(t, s.Pop().Item())
|
||||||
|
require.Equal(t, newGroupName, group.Name)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("set group KVs", func(t *testing.T) {
|
||||||
|
iamARN := "arn"
|
||||||
|
|
||||||
|
anonInvoker.InvokeFail(t, notWitnessedError, setGroupKVMethod, nsName, groupID, client.IAMARNKey, iamARN)
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, setGroupKVMethod, nsName, groupID, client.IAMARNKey, iamARN)
|
||||||
|
|
||||||
|
s, err = anonInvoker.TestInvoke(t, getGroupMethod, nsName, groupID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
group = parseGroup(t, s.Pop().Item())
|
||||||
|
require.Equal(t, iamARN, group.KV[client.IAMARNKey])
|
||||||
|
|
||||||
|
anonInvoker.InvokeFail(t, notWitnessedError, deleteGroupKVMethod, nsName, groupID, client.IAMARNKey)
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, deleteGroupKVMethod, nsName, groupID, client.IAMARNKey)
|
||||||
|
|
||||||
|
s, err = anonInvoker.TestInvoke(t, getGroupMethod, nsName, groupID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
group = parseGroup(t, s.Pop().Item())
|
||||||
|
require.Empty(t, group.KV)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("delete group", func(t *testing.T) {
|
||||||
|
anonInvoker.InvokeFail(t, notWitnessedError, deleteGroupMethod, nsName, groupID)
|
||||||
|
invoker.Invoke(t, stackitem.Null{}, deleteGroupMethod, nsName, groupID)
|
||||||
|
|
||||||
|
anonInvoker.InvokeFail(t, "group not found", getGroupMethod, nsName, groupID)
|
||||||
|
|
||||||
|
s, err = anonInvoker.TestInvoke(t, listGroupsMethod, nsName)
|
||||||
|
require.NoError(t, err)
|
||||||
|
groups := parseGroups(t, readIteratorAll(s))
|
||||||
|
require.Empty(t, groups)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkPublicKeyResult(t *testing.T, s *vm.Stack, err error, key *keys.PrivateKey) {
|
||||||
|
if key == nil {
|
||||||
|
require.ErrorContains(t, err, "not found")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
require.NoError(t, err)
|
||||||
|
foundKey, err := unwrap.PublicKey(makeValidRes(s.Pop().Item()), nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, key.PublicKey(), foundKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkGroupIDResult(t *testing.T, s *vm.Stack, err error, groupID int64) {
|
||||||
|
if groupID == -1 {
|
||||||
|
require.ErrorContains(t, err, "not found")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
require.NoError(t, err)
|
||||||
|
foundGroupID, err := unwrap.Int64(makeValidRes(s.Pop().Item()), nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, groupID, foundGroupID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func readIteratorAll(s *vm.Stack) []stackitem.Item {
|
||||||
|
iter := s.Pop().Value().(*storage.Iterator)
|
||||||
|
|
||||||
|
stackItems := make([]stackitem.Item, 0)
|
||||||
|
for iter.Next() {
|
||||||
|
stackItems = append(stackItems, iter.Value())
|
||||||
|
}
|
||||||
|
|
||||||
|
return stackItems
|
||||||
|
}
|
||||||
|
|
||||||
|
type Subject struct {
|
||||||
|
PrimaryKey keys.PublicKey
|
||||||
|
AdditionalKeys keys.PublicKeys
|
||||||
|
Namespace string
|
||||||
|
Name string
|
||||||
|
KV map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseSubject(t *testing.T, s *vm.Stack) Subject {
|
||||||
|
var subj Subject
|
||||||
|
|
||||||
|
subjStruct := s.Pop().Array()
|
||||||
|
require.Len(t, subjStruct, 5)
|
||||||
|
|
||||||
|
pkBytes, err := subjStruct[0].TryBytes()
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = subj.PrimaryKey.DecodeBytes(pkBytes)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
if !subjStruct[1].Equals(stackitem.Null{}) {
|
||||||
|
subj.AdditionalKeys, err = unwrap.ArrayOfPublicKeys(makeValidRes(subjStruct[1]), nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
nsBytes, err := subjStruct[2].TryBytes()
|
||||||
|
require.NoError(t, err)
|
||||||
|
subj.Namespace = string(nsBytes)
|
||||||
|
|
||||||
|
nameBytes, err := subjStruct[3].TryBytes()
|
||||||
|
require.NoError(t, err)
|
||||||
|
subj.Name = string(nameBytes)
|
||||||
|
|
||||||
|
subj.KV, err = parseMap(subjStruct[4])
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
return subj
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseMap(item stackitem.Item) (map[string]string, error) {
|
||||||
|
if item.Equals(stackitem.Null{}) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
metaMap, err := unwrap.Map(makeValidRes(item), nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
meta, ok := metaMap.Value().([]stackitem.MapElement)
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("invalid map type")
|
||||||
|
}
|
||||||
|
|
||||||
|
res := make(map[string]string, len(meta))
|
||||||
|
for _, element := range meta {
|
||||||
|
key, err := element.Key.TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
val, err := element.Value.TryBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
res[string(key)] = string(val)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type Namespace struct {
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
type NamespaceExtended struct {
|
||||||
|
Name string
|
||||||
|
SubjectsCount int64
|
||||||
|
GroupsCount int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseNamespace(t *testing.T, item stackitem.Item) Namespace {
|
||||||
|
var ns Namespace
|
||||||
|
|
||||||
|
subjStruct := item.Value().([]stackitem.Item)
|
||||||
|
require.Len(t, subjStruct, 1)
|
||||||
|
|
||||||
|
nameBytes, err := subjStruct[0].TryBytes()
|
||||||
|
require.NoError(t, err)
|
||||||
|
ns.Name = string(nameBytes)
|
||||||
|
|
||||||
|
return ns
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseNamespaceExtended(t *testing.T, item stackitem.Item) NamespaceExtended {
|
||||||
|
var ns NamespaceExtended
|
||||||
|
|
||||||
|
subjStruct := item.Value().([]stackitem.Item)
|
||||||
|
require.Len(t, subjStruct, 3)
|
||||||
|
|
||||||
|
nameBytes, err := subjStruct[0].TryBytes()
|
||||||
|
require.NoError(t, err)
|
||||||
|
ns.Name = string(nameBytes)
|
||||||
|
|
||||||
|
groupCountInt, err := subjStruct[1].TryInteger()
|
||||||
|
require.NoError(t, err)
|
||||||
|
ns.GroupsCount = groupCountInt.Int64()
|
||||||
|
|
||||||
|
subjectsCountInt, err := subjStruct[2].TryInteger()
|
||||||
|
require.NoError(t, err)
|
||||||
|
ns.SubjectsCount = subjectsCountInt.Int64()
|
||||||
|
|
||||||
|
return ns
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseNamespaces(t *testing.T, items []stackitem.Item) []Namespace {
|
||||||
|
res := make([]Namespace, len(items))
|
||||||
|
|
||||||
|
for i := 0; i < len(items); i++ {
|
||||||
|
res[i] = parseNamespace(t, items[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
type Group struct {
|
||||||
|
ID int64
|
||||||
|
Name string
|
||||||
|
Namespace string
|
||||||
|
KV map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
type GroupExtended struct {
|
||||||
|
ID int64
|
||||||
|
Name string
|
||||||
|
Namespace string
|
||||||
|
KV map[string]string
|
||||||
|
SubjectsCount int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseGroup(t *testing.T, item stackitem.Item) Group {
|
||||||
|
var group Group
|
||||||
|
|
||||||
|
subjStruct := item.Value().([]stackitem.Item)
|
||||||
|
require.Len(t, subjStruct, 4)
|
||||||
|
|
||||||
|
groupID, err := subjStruct[0].TryInteger()
|
||||||
|
require.NoError(t, err)
|
||||||
|
group.ID = groupID.Int64()
|
||||||
|
|
||||||
|
nameBytes, err := subjStruct[1].TryBytes()
|
||||||
|
require.NoError(t, err)
|
||||||
|
group.Name = string(nameBytes)
|
||||||
|
|
||||||
|
namespaceBytes, err := subjStruct[2].TryBytes()
|
||||||
|
require.NoError(t, err)
|
||||||
|
group.Namespace = string(namespaceBytes)
|
||||||
|
|
||||||
|
group.KV, err = parseMap(subjStruct[3])
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
return group
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseGroupExtended(t *testing.T, item stackitem.Item) GroupExtended {
|
||||||
|
var gr GroupExtended
|
||||||
|
|
||||||
|
subjStruct := item.Value().([]stackitem.Item)
|
||||||
|
require.Len(t, subjStruct, 5)
|
||||||
|
|
||||||
|
groupID, err := subjStruct[0].TryInteger()
|
||||||
|
require.NoError(t, err)
|
||||||
|
gr.ID = groupID.Int64()
|
||||||
|
|
||||||
|
nameBytes, err := subjStruct[1].TryBytes()
|
||||||
|
require.NoError(t, err)
|
||||||
|
gr.Name = string(nameBytes)
|
||||||
|
|
||||||
|
namespaceBytes, err := subjStruct[2].TryBytes()
|
||||||
|
require.NoError(t, err)
|
||||||
|
gr.Namespace = string(namespaceBytes)
|
||||||
|
|
||||||
|
gr.KV, err = parseMap(subjStruct[3])
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
subjectsCountInt, err := subjStruct[4].TryInteger()
|
||||||
|
require.NoError(t, err)
|
||||||
|
gr.SubjectsCount = subjectsCountInt.Int64()
|
||||||
|
|
||||||
|
return gr
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseGroups(t *testing.T, items []stackitem.Item) []Group {
|
||||||
|
res := make([]Group, len(items))
|
||||||
|
|
||||||
|
for i := 0; i < len(items); i++ {
|
||||||
|
res[i] = parseGroup(t, items[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeValidRes(item stackitem.Item) *result.Invoke {
|
||||||
|
return &result.Invoke{
|
||||||
|
Stack: []stackitem.Item{item},
|
||||||
|
State: vmstate.Halt.String(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -20,23 +20,22 @@ import (
|
||||||
|
|
||||||
const netmapPath = "../netmap"
|
const netmapPath = "../netmap"
|
||||||
|
|
||||||
func deployNetmapContract(t *testing.T, e *neotest.Executor, addrBalance, addrContainer util.Uint160, config ...interface{}) util.Uint160 {
|
func deployNetmapContract(t *testing.T, e *neotest.Executor, addrBalance, addrContainer util.Uint160, config ...any) util.Uint160 {
|
||||||
_, pubs, ok := vm.ParseMultiSigContract(e.Committee.Script())
|
_, pubs, ok := vm.ParseMultiSigContract(e.Committee.Script())
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
|
||||||
args := make([]interface{}, 5)
|
args := make([]any, 4)
|
||||||
args[0] = false
|
args[0] = addrBalance
|
||||||
args[1] = addrBalance
|
args[1] = addrContainer
|
||||||
args[2] = addrContainer
|
args[2] = []any{pubs[0]}
|
||||||
args[3] = []interface{}{pubs[0]}
|
args[3] = append([]any{}, config...)
|
||||||
args[4] = append([]interface{}{}, config...)
|
|
||||||
|
|
||||||
c := neotest.CompileFile(t, e.CommitteeHash, netmapPath, path.Join(netmapPath, "config.yml"))
|
c := neotest.CompileFile(t, e.CommitteeHash, netmapPath, path.Join(netmapPath, "config.yml"))
|
||||||
e.DeployContract(t, c, args)
|
e.DeployContract(t, c, args)
|
||||||
return c.Hash
|
return c.Hash
|
||||||
}
|
}
|
||||||
|
|
||||||
func newNetmapInvoker(t *testing.T, config ...interface{}) *neotest.ContractInvoker {
|
func newNetmapInvoker(t *testing.T, config ...any) *neotest.ContractInvoker {
|
||||||
e := newExecutor(t)
|
e := newExecutor(t)
|
||||||
|
|
||||||
ctrNNS := neotest.CompileFile(t, e.CommitteeHash, nnsPath, path.Join(nnsPath, "config.yml"))
|
ctrNNS := neotest.CompileFile(t, e.CommitteeHash, nnsPath, path.Join(nnsPath, "config.yml"))
|
||||||
|
|
|
@ -115,7 +115,8 @@ func TestNNSRegister(t *testing.T) {
|
||||||
|
|
||||||
expected = stackitem.NewArray([]stackitem.Item{
|
expected = stackitem.NewArray([]stackitem.Item{
|
||||||
stackitem.NewByteArray([]byte("first TXT record")),
|
stackitem.NewByteArray([]byte("first TXT record")),
|
||||||
stackitem.NewByteArray([]byte("second TXT record"))})
|
stackitem.NewByteArray([]byte("second TXT record")),
|
||||||
|
})
|
||||||
c.Invoke(t, expected, "getRecords", "testdomain.com", int64(nns.TXT))
|
c.Invoke(t, expected, "getRecords", "testdomain.com", int64(nns.TXT))
|
||||||
|
|
||||||
cAcc.Invoke(t, stackitem.Null{}, "setRecord",
|
cAcc.Invoke(t, stackitem.Null{}, "setRecord",
|
||||||
|
@ -123,7 +124,8 @@ func TestNNSRegister(t *testing.T) {
|
||||||
|
|
||||||
expected = stackitem.NewArray([]stackitem.Item{
|
expected = stackitem.NewArray([]stackitem.Item{
|
||||||
stackitem.NewByteArray([]byte("replaced first")),
|
stackitem.NewByteArray([]byte("replaced first")),
|
||||||
stackitem.NewByteArray([]byte("second TXT record"))})
|
stackitem.NewByteArray([]byte("second TXT record")),
|
||||||
|
})
|
||||||
c.Invoke(t, expected, "getRecords", "testdomain.com", int64(nns.TXT))
|
c.Invoke(t, expected, "getRecords", "testdomain.com", int64(nns.TXT))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,8 +141,8 @@ func TestTLDRecord(t *testing.T) {
|
||||||
func TestNNSRegisterMulti(t *testing.T) {
|
func TestNNSRegisterMulti(t *testing.T) {
|
||||||
c := newNNSInvoker(t, true)
|
c := newNNSInvoker(t, true)
|
||||||
|
|
||||||
newArgs := func(domain string, account neotest.Signer) []interface{} {
|
newArgs := func(domain string, account neotest.Signer) []any {
|
||||||
return []interface{}{
|
return []any{
|
||||||
domain, account.ScriptHash(), "doesnt@matter.com",
|
domain, account.ScriptHash(), "doesnt@matter.com",
|
||||||
int64(101), int64(102), int64(103), int64(104),
|
int64(101), int64(102), int64(103), int64(104),
|
||||||
}
|
}
|
||||||
|
@ -185,7 +187,8 @@ func TestNNSRegisterMulti(t *testing.T) {
|
||||||
c2.Invoke(t, stackitem.Null{}, "addRecord",
|
c2.Invoke(t, stackitem.Null{}, "addRecord",
|
||||||
"cdn.mainnet.fs.neo.com", int64(nns.A), "166.15.14.13")
|
"cdn.mainnet.fs.neo.com", int64(nns.A), "166.15.14.13")
|
||||||
result := stackitem.NewArray([]stackitem.Item{
|
result := stackitem.NewArray([]stackitem.Item{
|
||||||
stackitem.NewByteArray([]byte("166.15.14.13"))})
|
stackitem.NewByteArray([]byte("166.15.14.13")),
|
||||||
|
})
|
||||||
c2.Invoke(t, result, "resolve", "cdn.mainnet.fs.neo.com", int64(nns.A))
|
c2.Invoke(t, result, "resolve", "cdn.mainnet.fs.neo.com", int64(nns.A))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,7 +265,8 @@ func TestExpiration(t *testing.T) {
|
||||||
checkProperties := func(t *testing.T, expiration uint64) {
|
checkProperties := func(t *testing.T, expiration uint64) {
|
||||||
expected := stackitem.NewMapWithValue([]stackitem.MapElement{
|
expected := stackitem.NewMapWithValue([]stackitem.MapElement{
|
||||||
{Key: stackitem.Make("name"), Value: stackitem.Make("testdomain.com")},
|
{Key: stackitem.Make("name"), Value: stackitem.Make("testdomain.com")},
|
||||||
{Key: stackitem.Make("expiration"), Value: stackitem.Make(expiration)}})
|
{Key: stackitem.Make("expiration"), Value: stackitem.Make(expiration)},
|
||||||
|
})
|
||||||
s, err := c.TestInvoke(t, "properties", "testdomain.com")
|
s, err := c.TestInvoke(t, "properties", "testdomain.com")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, expected.Value(), s.Top().Item().Value())
|
require.Equal(t, expected.Value(), s.Top().Item().Value())
|
||||||
|
@ -351,7 +355,8 @@ func TestNNSRenew(t *testing.T) {
|
||||||
c1.Invoke(t, ts, "renew", "testdomain.com")
|
c1.Invoke(t, ts, "renew", "testdomain.com")
|
||||||
expected := stackitem.NewMapWithValue([]stackitem.MapElement{
|
expected := stackitem.NewMapWithValue([]stackitem.MapElement{
|
||||||
{Key: stackitem.Make("name"), Value: stackitem.Make("testdomain.com")},
|
{Key: stackitem.Make("name"), Value: stackitem.Make("testdomain.com")},
|
||||||
{Key: stackitem.Make("expiration"), Value: stackitem.Make(ts)}})
|
{Key: stackitem.Make("expiration"), Value: stackitem.Make(ts)},
|
||||||
|
})
|
||||||
cAcc.Invoke(t, expected, "properties", "testdomain.com")
|
cAcc.Invoke(t, expected, "properties", "testdomain.com")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
127
tests/policy_test.go
Normal file
127
tests/policy_test.go
Normal file
|
@ -0,0 +1,127 @@
|
||||||
|
package tests
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"path"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-contract/policy"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/neotest"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
const policyPath = "../policy"
|
||||||
|
|
||||||
|
func deployPolicyContract(t *testing.T, e *neotest.Executor) util.Uint160 {
|
||||||
|
cfgPath := path.Join(policyPath, "config.yml")
|
||||||
|
c := neotest.CompileFile(t, e.CommitteeHash, policyPath, cfgPath)
|
||||||
|
e.DeployContract(t, c, []any{nil})
|
||||||
|
return c.Hash
|
||||||
|
}
|
||||||
|
|
||||||
|
func newPolicyInvoker(t *testing.T) *neotest.ContractInvoker {
|
||||||
|
e := newExecutor(t)
|
||||||
|
h := deployPolicyContract(t, e)
|
||||||
|
return e.CommitteeInvoker(h)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPolicy(t *testing.T) {
|
||||||
|
e := newPolicyInvoker(t)
|
||||||
|
|
||||||
|
// Policies are opaque to the contract and are just raw bytes to store.
|
||||||
|
p1 := []byte("chain1")
|
||||||
|
p2 := []byte("chain2")
|
||||||
|
p3 := []byte("chain3")
|
||||||
|
p33 := []byte("chain33")
|
||||||
|
|
||||||
|
e.Invoke(t, stackitem.Null{}, "addChain", policy.Namespace, "mynamespace", "ingress:123", p1)
|
||||||
|
checkChains(t, e, "mynamespace", "", "ingress", [][]byte{p1})
|
||||||
|
checkChains(t, e, "mynamespace", "", "all", nil)
|
||||||
|
|
||||||
|
e.Invoke(t, stackitem.Null{}, "addChain", policy.Container, "cnr1", "ingress:myrule2", p2)
|
||||||
|
checkChains(t, e, "mynamespace", "", "ingress", [][]byte{p1}) // Only namespace chains.
|
||||||
|
checkChains(t, e, "mynamespace", "cnr1", "ingress", [][]byte{p1, p2})
|
||||||
|
checkChains(t, e, "mynamespace", "cnr1", "all", nil) // No chains attached to 'all'.
|
||||||
|
checkChains(t, e, "mynamespace", "cnr2", "ingress", [][]byte{p1}) // Only namespace, no chains for the container.
|
||||||
|
|
||||||
|
e.Invoke(t, stackitem.Null{}, "addChain", policy.Container, "cnr1", "ingress:myrule3", p3)
|
||||||
|
checkChains(t, e, "mynamespace", "cnr1", "ingress", [][]byte{p1, p2, p3})
|
||||||
|
|
||||||
|
e.Invoke(t, stackitem.Null{}, "addChain", policy.Container, "cnr1", "ingress:myrule3", p33)
|
||||||
|
checkChain(t, e, policy.Container, "cnr1", "ingress:myrule3", p33)
|
||||||
|
checkChains(t, e, "mynamespace", "cnr1", "ingress", [][]byte{p1, p2, p33}) // Override chain.
|
||||||
|
checkChainsByPrefix(t, e, policy.Container, "cnr1", "", [][]byte{p2, p33})
|
||||||
|
checkChainsByPrefix(t, e, policy.IAM, "", "", nil)
|
||||||
|
|
||||||
|
t.Run("removal", func(t *testing.T) {
|
||||||
|
t.Run("wrong name", func(t *testing.T) {
|
||||||
|
e.Invoke(t, stackitem.Null{}, "removeChain", policy.Namespace, "mynamespace", "ingress")
|
||||||
|
checkChains(t, e, "mynamespace", "", "ingress", [][]byte{p1})
|
||||||
|
})
|
||||||
|
|
||||||
|
e.Invoke(t, stackitem.Null{}, "removeChain", policy.Namespace, "mynamespace", "ingress:123")
|
||||||
|
checkChains(t, e, "mynamespace", "", "ingress", nil)
|
||||||
|
checkChains(t, e, "mynamespace", "cnr1", "ingress", [][]byte{p2, p33}) // Container chains still exist.
|
||||||
|
|
||||||
|
// Remove by prefix.
|
||||||
|
e.Invoke(t, stackitem.Null{}, "removeChainsByPrefix", policy.Container, "cnr1", "ingress")
|
||||||
|
checkChains(t, e, "mynamespace", "cnr1", "ingress", nil)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAutorization(t *testing.T) {
|
||||||
|
e := newPolicyInvoker(t)
|
||||||
|
|
||||||
|
e.Invoke(t, stackitem.Null{}, "getAdmin")
|
||||||
|
|
||||||
|
s := e.NewAccount(t, 1_0000_0000)
|
||||||
|
c := e.WithSigners(s)
|
||||||
|
|
||||||
|
args := []any{policy.Container, "cnr1", "ingress:myrule3", []byte("opaque")}
|
||||||
|
c.InvokeFail(t, policy.ErrNotAuthorized, "addChain", args...)
|
||||||
|
|
||||||
|
e.Invoke(t, stackitem.Null{}, "setAdmin", s.ScriptHash())
|
||||||
|
e.Invoke(t, stackitem.NewBuffer(s.ScriptHash().BytesBE()), "getAdmin")
|
||||||
|
|
||||||
|
c.Invoke(t, stackitem.Null{}, "addChain", args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkChains(t *testing.T, e *neotest.ContractInvoker, namespace, container, name string, expected [][]byte) {
|
||||||
|
s, err := e.TestInvoke(t, "listChains", namespace, container, name)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
checksChainsOnStack(t, s, expected)
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkChainsByPrefix(t *testing.T, e *neotest.ContractInvoker, kind byte, entityName, prefix string, expected [][]byte) {
|
||||||
|
s, err := e.TestInvoke(t, "listChainsByPrefix", kind, entityName, prefix)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
checksChainsOnStack(t, s, expected)
|
||||||
|
}
|
||||||
|
|
||||||
|
func checksChainsOnStack(t *testing.T, s *vm.Stack, expected [][]byte) {
|
||||||
|
require.Equal(t, 1, s.Len())
|
||||||
|
|
||||||
|
var actual [][]byte
|
||||||
|
arr := s.Pop().Array()
|
||||||
|
for i := range arr {
|
||||||
|
bs, err := arr[i].TryBytes()
|
||||||
|
|
||||||
|
require.NoError(t, err)
|
||||||
|
actual = append(actual, bs)
|
||||||
|
}
|
||||||
|
|
||||||
|
require.ElementsMatch(t, expected, actual)
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkChain(t *testing.T, e *neotest.ContractInvoker, kind byte, entityName, name string, expected []byte) {
|
||||||
|
s, err := e.TestInvoke(t, "getChain", kind, entityName, name)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, 1, s.Len())
|
||||||
|
|
||||||
|
require.True(t, bytes.Equal(expected, s.Pop().Bytes()))
|
||||||
|
}
|
|
@ -14,7 +14,7 @@ const processingPath = "../processing"
|
||||||
func deployProcessingContract(t *testing.T, e *neotest.Executor, addrFrostFS util.Uint160) util.Uint160 {
|
func deployProcessingContract(t *testing.T, e *neotest.Executor, addrFrostFS util.Uint160) util.Uint160 {
|
||||||
c := neotest.CompileFile(t, e.CommitteeHash, processingPath, path.Join(processingPath, "config.yml"))
|
c := neotest.CompileFile(t, e.CommitteeHash, processingPath, path.Join(processingPath, "config.yml"))
|
||||||
|
|
||||||
args := make([]interface{}, 1)
|
args := make([]any, 1)
|
||||||
args[0] = addrFrostFS
|
args[0] = addrFrostFS
|
||||||
|
|
||||||
e.DeployContract(t, c, args)
|
e.DeployContract(t, c, args)
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
const proxyPath = "../proxy"
|
const proxyPath = "../proxy"
|
||||||
|
|
||||||
func deployProxyContract(t *testing.T, e *neotest.Executor, addrNetmap util.Uint160) util.Uint160 {
|
func deployProxyContract(t *testing.T, e *neotest.Executor, addrNetmap util.Uint160) util.Uint160 {
|
||||||
args := make([]interface{}, 1)
|
args := make([]any, 1)
|
||||||
args[0] = addrNetmap
|
args[0] = addrNetmap
|
||||||
|
|
||||||
c := neotest.CompileFile(t, e.CommitteeHash, proxyPath, path.Join(proxyPath, "config.yml"))
|
c := neotest.CompileFile(t, e.CommitteeHash, proxyPath, path.Join(proxyPath, "config.yml"))
|
||||||
|
|
|
@ -1,80 +0,0 @@
|
||||||
package tests
|
|
||||||
|
|
||||||
import (
|
|
||||||
"path"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/neotest"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/neotest/chain"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
|
||||||
)
|
|
||||||
|
|
||||||
const reputationPath = "../reputation"
|
|
||||||
|
|
||||||
func deployReputationContract(t *testing.T, e *neotest.Executor) util.Uint160 {
|
|
||||||
c := neotest.CompileFile(t, e.CommitteeHash, reputationPath,
|
|
||||||
path.Join(reputationPath, "config.yml"))
|
|
||||||
|
|
||||||
args := make([]interface{}, 1)
|
|
||||||
args[0] = false
|
|
||||||
|
|
||||||
e.DeployContract(t, c, args)
|
|
||||||
return c.Hash
|
|
||||||
}
|
|
||||||
|
|
||||||
func newReputationInvoker(t *testing.T) *neotest.ContractInvoker {
|
|
||||||
bc, acc := chain.NewSingle(t)
|
|
||||||
e := neotest.NewExecutor(t, bc, acc, acc)
|
|
||||||
h := deployReputationContract(t, e)
|
|
||||||
return e.CommitteeInvoker(h)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestReputation_Put(t *testing.T) {
|
|
||||||
e := newReputationInvoker(t)
|
|
||||||
|
|
||||||
peerID := []byte{1, 2, 3}
|
|
||||||
e.Invoke(t, stackitem.Null{}, "put", int64(1), peerID, []byte{4})
|
|
||||||
|
|
||||||
t.Run("concurrent invocations", func(t *testing.T) {
|
|
||||||
repValue1 := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
|
|
||||||
repValue2 := []byte{10, 20, 30, 40, 50, 60, 70, 80}
|
|
||||||
tx1 := e.PrepareInvoke(t, "put", int64(1), peerID, repValue1)
|
|
||||||
tx2 := e.PrepareInvoke(t, "put", int64(1), peerID, repValue2)
|
|
||||||
|
|
||||||
e.AddNewBlock(t, tx1, tx2)
|
|
||||||
e.CheckHalt(t, tx1.Hash(), stackitem.Null{})
|
|
||||||
e.CheckHalt(t, tx2.Hash(), stackitem.Null{})
|
|
||||||
|
|
||||||
t.Run("get all", func(t *testing.T) {
|
|
||||||
result := stackitem.NewArray([]stackitem.Item{
|
|
||||||
stackitem.NewBuffer([]byte{4}),
|
|
||||||
stackitem.NewBuffer(repValue1),
|
|
||||||
stackitem.NewBuffer(repValue2),
|
|
||||||
})
|
|
||||||
e.Invoke(t, result, "get", int64(1), peerID)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestReputation_ListByEpoch(t *testing.T) {
|
|
||||||
e := newReputationInvoker(t)
|
|
||||||
|
|
||||||
peerIDs := []string{"peer1", "peer2"}
|
|
||||||
e.Invoke(t, stackitem.Null{}, "put", int64(1), peerIDs[0], []byte{1})
|
|
||||||
e.Invoke(t, stackitem.Null{}, "put", int64(1), peerIDs[0], []byte{2})
|
|
||||||
e.Invoke(t, stackitem.Null{}, "put", int64(2), peerIDs[1], []byte{3})
|
|
||||||
e.Invoke(t, stackitem.Null{}, "put", int64(2), peerIDs[0], []byte{4})
|
|
||||||
e.Invoke(t, stackitem.Null{}, "put", int64(2), peerIDs[1], []byte{5})
|
|
||||||
|
|
||||||
result := stackitem.NewArray([]stackitem.Item{
|
|
||||||
stackitem.NewBuffer(append([]byte{1}, peerIDs[0]...)),
|
|
||||||
})
|
|
||||||
e.Invoke(t, result, "listByEpoch", int64(1))
|
|
||||||
|
|
||||||
result = stackitem.NewArray([]stackitem.Item{
|
|
||||||
stackitem.NewBuffer(append([]byte{2}, peerIDs[0]...)),
|
|
||||||
stackitem.NewBuffer(append([]byte{2}, peerIDs[1]...)),
|
|
||||||
})
|
|
||||||
e.Invoke(t, result, "listByEpoch", int64(2))
|
|
||||||
}
|
|
2
tests/testdata/config.yml
vendored
Normal file
2
tests/testdata/config.yml
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
name: "TestContract"
|
||||||
|
safemethods: ["encodeDecode"]
|
17
tests/testdata/encode.go
vendored
Normal file
17
tests/testdata/encode.go
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package testdata
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-contract/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
// EncodeDecode encodes x in fixed-width little-endian representation
|
||||||
|
// and deserializes it back.
|
||||||
|
func EncodeDecode(x int) int {
|
||||||
|
y := common.ToFixedWidth64(x)
|
||||||
|
return common.FromFixedWidth64(y)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Encode encodes x in fixed-width little-endian representation.
|
||||||
|
func Encode(x int) []byte {
|
||||||
|
return common.ToFixedWidth64(x)
|
||||||
|
}
|
205
tests/util.go
205
tests/util.go
|
@ -1,14 +1,76 @@
|
||||||
package tests
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/consensus"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop/storage"
|
"github.com/nspcc-dev/neo-go/pkg/core/interop/storage"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
|
corestate "github.com/nspcc-dev/neo-go/pkg/core/stateroot"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/neotest"
|
"github.com/nspcc-dev/neo-go/pkg/neotest"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/neotest/chain"
|
"github.com/nspcc-dev/neo-go/pkg/neotest/chain"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/network"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/services/rpcsrv"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/services/stateroot"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type awaiter struct {
|
||||||
|
ctx context.Context
|
||||||
|
t *testing.T
|
||||||
|
rpc *rpcclient.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a awaiter) await(tx util.Uint256, vub uint32, err error) *state.AppExecResult {
|
||||||
|
require.NoError(a.t, err)
|
||||||
|
return await(a.ctx, a.t, a.rpc, tx, vub)
|
||||||
|
}
|
||||||
|
|
||||||
|
const nodeWallet = `
|
||||||
|
{
|
||||||
|
"version": "3.0",
|
||||||
|
"accounts": [
|
||||||
|
{
|
||||||
|
"address": "Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn",
|
||||||
|
"key": "6PYM8VdX2BSm7BSXKzV4Fz6S3R9cDLLWNrD9nMjxW352jEv3fsC8N3wNLY",
|
||||||
|
"label": "",
|
||||||
|
"contract": {
|
||||||
|
"script": "DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcJBVuezJw==",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "parameter0",
|
||||||
|
"type": "Signature"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"deployed": false
|
||||||
|
},
|
||||||
|
"lock": false,
|
||||||
|
"isdefault": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"scrypt": {
|
||||||
|
"n": 16384,
|
||||||
|
"r": 8,
|
||||||
|
"p": 8
|
||||||
|
},
|
||||||
|
"extra": {
|
||||||
|
"Tokens": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
func iteratorToArray(iter *storage.Iterator) []stackitem.Item {
|
func iteratorToArray(iter *storage.Iterator) []stackitem.Item {
|
||||||
stackItems := make([]stackitem.Item, 0)
|
stackItems := make([]stackitem.Item, 0)
|
||||||
for iter.Next() {
|
for iter.Next() {
|
||||||
|
@ -21,3 +83,146 @@ func newExecutor(t *testing.T) *neotest.Executor {
|
||||||
bc, acc := chain.NewSingle(t)
|
bc, acc := chain.NewSingle(t)
|
||||||
return neotest.NewExecutor(t, bc, acc, acc)
|
return neotest.NewExecutor(t, bc, acc, acc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initTmpWallet(t *testing.T) string {
|
||||||
|
f, err := os.CreateTemp("", "tmp-neo-go-wallet")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
_, err = f.WriteString(nodeWallet)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
err = f.Close()
|
||||||
|
require.NoError(t, err)
|
||||||
|
return f.Name()
|
||||||
|
}
|
||||||
|
|
||||||
|
func await(ctx context.Context, t *testing.T, rpc *rpcclient.Client, tx util.Uint256, vub uint32) *state.AppExecResult {
|
||||||
|
waitCtx, waitCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||||
|
defer waitCancel()
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-waitCtx.Done():
|
||||||
|
require.NoError(t, waitCtx.Err())
|
||||||
|
return nil
|
||||||
|
default:
|
||||||
|
bc, err := rpc.GetBlockCount()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
tr := trigger.Application
|
||||||
|
if log, err := rpc.GetApplicationLog(tx, &tr); err == nil {
|
||||||
|
return &state.AppExecResult{
|
||||||
|
Container: log.Container,
|
||||||
|
Execution: log.Executions[0],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
require.LessOrEqual(t, bc, vub, "vub is expired")
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func neogoCfg() config.Config {
|
||||||
|
return config.Config{
|
||||||
|
ProtocolConfiguration: config.ProtocolConfiguration{},
|
||||||
|
ApplicationConfiguration: config.ApplicationConfiguration{
|
||||||
|
RPC: config.RPC{
|
||||||
|
BasicService: config.BasicService{
|
||||||
|
Enabled: true,
|
||||||
|
// See how tests are done in the neo-go itself:
|
||||||
|
// https://github.com/nspcc-dev/neo-go/blob/5fc61be5f6c5349d8de8b61967380feee6b51c55/config/protocol.unit_testnet.single.yml#L61
|
||||||
|
Addresses: []string{"localhost:0"},
|
||||||
|
},
|
||||||
|
MaxGasInvoke: 200_000_000,
|
||||||
|
SessionEnabled: true,
|
||||||
|
MaxIteratorResultItems: 100,
|
||||||
|
SessionPoolSize: 20,
|
||||||
|
SessionExpirationTime: 15,
|
||||||
|
},
|
||||||
|
DBConfiguration: dbconfig.DBConfiguration{
|
||||||
|
Type: dbconfig.InMemoryDB,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func consensusCfg(chain *core.Blockchain, walletAddress string, srv *network.Server) consensus.Config {
|
||||||
|
return consensus.Config{
|
||||||
|
Logger: zap.NewExample(),
|
||||||
|
Broadcast: srv.BroadcastExtensible,
|
||||||
|
BlockQueue: srv.GetBlockQueue(),
|
||||||
|
Chain: chain,
|
||||||
|
ProtocolConfiguration: chain.GetConfig().ProtocolConfiguration,
|
||||||
|
RequestTx: srv.RequestTx,
|
||||||
|
StopTxFlow: srv.StopTxFlow,
|
||||||
|
Wallet: config.Wallet{
|
||||||
|
Path: walletAddress,
|
||||||
|
Password: "one",
|
||||||
|
},
|
||||||
|
TimePerBlock: 100 * time.Millisecond,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func runRPC(ctx context.Context, t *testing.T, chain *core.Blockchain, walletPath string) string {
|
||||||
|
log := zap.NewExample()
|
||||||
|
cfg := neogoCfg()
|
||||||
|
|
||||||
|
srvCfg, err := network.NewServerConfig(cfg)
|
||||||
|
require.NoError(t, err)
|
||||||
|
srv, err := network.NewServer(srvCfg, chain, chain.GetStateSyncModule(), log)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
t.Cleanup(srv.Shutdown)
|
||||||
|
|
||||||
|
errCh := make(chan error)
|
||||||
|
go func() {
|
||||||
|
for err := range errCh {
|
||||||
|
require.NoError(t, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
srMod := chain.GetStateModule().(*corestate.Module)
|
||||||
|
sr, err := stateroot.New(srvCfg.StateRootCfg, srMod, log, chain, srv.BroadcastExtensible)
|
||||||
|
require.NoError(t, err)
|
||||||
|
srv.AddExtensibleService(sr, stateroot.Category, sr.OnPayload)
|
||||||
|
|
||||||
|
consens, err := consensus.NewService(consensusCfg(chain, walletPath, srv))
|
||||||
|
require.NoError(t, err)
|
||||||
|
srv.AddConsensusService(consens, consens.OnPayload, consens.OnTransaction)
|
||||||
|
|
||||||
|
rpcSrv := rpcsrv.New(chain, cfg.ApplicationConfiguration.RPC, srv, nil, log, errCh)
|
||||||
|
srv.AddService(&rpcSrv)
|
||||||
|
|
||||||
|
initialAddr := rpcSrv.Addresses()[0]
|
||||||
|
|
||||||
|
go srv.Start()
|
||||||
|
|
||||||
|
// wait until RPC server is started
|
||||||
|
startTimeout, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
ticker := time.NewTicker(time.Millisecond * 100)
|
||||||
|
defer ticker.Stop()
|
||||||
|
|
||||||
|
var actualAddr string
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-startTimeout.Done():
|
||||||
|
t.Fatalf("Waiting for server start: %v", startTimeout.Err())
|
||||||
|
case <-ticker.C:
|
||||||
|
if actualAddr == "" {
|
||||||
|
newAddr := rpcSrv.Addresses()[0]
|
||||||
|
if initialAddr == newAddr {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
actualAddr = newAddr
|
||||||
|
t.Logf("RPC server is listening at %s, checking health", actualAddr)
|
||||||
|
}
|
||||||
|
if _, err = http.Get("http://" + actualAddr); err == nil {
|
||||||
|
return actualAddr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue