forked from TrueCloudLab/frostfs-contract
[#47] Update contract.Call invocations
Now contract calls require call flags. Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
fd803ef639
commit
27ca675869
4 changed files with 17 additions and 16 deletions
|
@ -74,7 +74,7 @@ func Neo() int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func balance(hash string, addr []byte) int {
|
func balance(hash string, addr []byte) int {
|
||||||
balance := contract.Call([]byte(hash), "balanceOf", addr)
|
balance := contract.Call([]byte(hash), "balanceOf", contract.ReadOnly, addr)
|
||||||
return balance.(int)
|
return balance.(int)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ func irList() []common.IRNode {
|
||||||
|
|
||||||
func currentEpoch() int {
|
func currentEpoch() int {
|
||||||
netmapContractAddr := storage.Get(ctx, netmapKey).([]byte)
|
netmapContractAddr := storage.Get(ctx, netmapKey).([]byte)
|
||||||
return contract.Call(netmapContractAddr, "epoch").(int)
|
return contract.Call(netmapContractAddr, "epoch", contract.ReadOnly).(int)
|
||||||
}
|
}
|
||||||
|
|
||||||
func name() string {
|
func name() string {
|
||||||
|
@ -119,7 +119,7 @@ func Emit() bool {
|
||||||
contractHash := runtime.GetExecutingScriptHash()
|
contractHash := runtime.GetExecutingScriptHash()
|
||||||
neo := balance(neoHash, contractHash)
|
neo := balance(neoHash, contractHash)
|
||||||
|
|
||||||
_ = contract.Call([]byte(neoHash), "transfer", contractHash, contractHash, neo, nil)
|
_ = contract.Call([]byte(neoHash), "transfer", contract.All, contractHash, contractHash, neo, nil)
|
||||||
|
|
||||||
gas := balance(gasHash, contractHash)
|
gas := balance(gasHash, contractHash)
|
||||||
gasPerNode := gas * 7 / 8 / len(innerRingKeys)
|
gasPerNode := gas * 7 / 8 / len(innerRingKeys)
|
||||||
|
@ -133,7 +133,7 @@ func Emit() bool {
|
||||||
node := innerRingKeys[i]
|
node := innerRingKeys[i]
|
||||||
address := contract.CreateStandardAccount(node.PublicKey)
|
address := contract.CreateStandardAccount(node.PublicKey)
|
||||||
|
|
||||||
_ = contract.Call([]byte(gasHash), "transfer", contractHash, address, gasPerNode, nil)
|
_ = contract.Call([]byte(gasHash), "transfer", contract.All, contractHash, address, gasPerNode, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime.Log("utility token has been emitted to inner ring nodes")
|
runtime.Log("utility token has been emitted to inner ring nodes")
|
||||||
|
@ -163,7 +163,7 @@ func Vote(epoch int, candidates [][]byte) {
|
||||||
candidate := candidates[index%len(candidates)]
|
candidate := candidates[index%len(candidates)]
|
||||||
address := runtime.GetExecutingScriptHash()
|
address := runtime.GetExecutingScriptHash()
|
||||||
|
|
||||||
ok := contract.Call([]byte(neoHash), "vote", address, candidate).(bool)
|
ok := contract.Call([]byte(neoHash), "vote", contract.All, address, candidate).(bool)
|
||||||
if ok {
|
if ok {
|
||||||
runtime.Log(name + ": successfully voted for validator")
|
runtime.Log(name + ": successfully voted for validator")
|
||||||
removeVotes(ctx, id)
|
removeVotes(ctx, id)
|
||||||
|
|
|
@ -37,5 +37,5 @@ func InnerRingListViaStorage(ctx storage.Context, key interface{}) []IRNode {
|
||||||
// InnerRingList gets list of inner ring through
|
// InnerRingList gets list of inner ring through
|
||||||
// calling "innerRingList" method of smart contract.
|
// calling "innerRingList" method of smart contract.
|
||||||
func InnerRingList(sc interop.Hash160) []IRNode {
|
func InnerRingList(sc interop.Hash160) []IRNode {
|
||||||
return contract.Call(sc, irListMethod).([]IRNode)
|
return contract.Call(sc, irListMethod, contract.ReadOnly).([]IRNode)
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,7 @@ func Put(container, signature, publicKey []byte) bool {
|
||||||
// check provided key
|
// check provided key
|
||||||
if !isSignedByOwnerKey(container, signature, ownerID, publicKey) {
|
if !isSignedByOwnerKey(container, signature, ownerID, publicKey) {
|
||||||
// check keys from NeoFSID
|
// check keys from NeoFSID
|
||||||
keys := contract.Call(neofsIDContractAddr, "key", ownerID).([][]byte)
|
keys := contract.Call(neofsIDContractAddr, "key", contract.ReadOnly, ownerID).([][]byte)
|
||||||
if !verifySignature(container, signature, keys) {
|
if !verifySignature(container, signature, keys) {
|
||||||
panic("put: invalid owner signature")
|
panic("put: invalid owner signature")
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ func Put(container, signature, publicKey []byte) bool {
|
||||||
|
|
||||||
from := walletToScripHash(ownerID)
|
from := walletToScripHash(ownerID)
|
||||||
balanceContractAddr := storage.Get(ctx, balanceContractKey).([]byte)
|
balanceContractAddr := storage.Get(ctx, balanceContractKey).([]byte)
|
||||||
containerFee := contract.Call(netmapContractAddr, "config", containerFeeKey).(int)
|
containerFee := contract.Call(netmapContractAddr, "config", contract.ReadOnly, containerFeeKey).(int)
|
||||||
hashCandidate := common.InvokeID([]interface{}{container, signature, publicKey}, []byte("put"))
|
hashCandidate := common.InvokeID([]interface{}{container, signature, publicKey}, []byte("put"))
|
||||||
|
|
||||||
n := common.Vote(ctx, hashCandidate, irKey)
|
n := common.Vote(ctx, hashCandidate, irKey)
|
||||||
|
@ -125,6 +125,7 @@ func Put(container, signature, publicKey []byte) bool {
|
||||||
to := contract.CreateStandardAccount(node.PublicKey)
|
to := contract.CreateStandardAccount(node.PublicKey)
|
||||||
|
|
||||||
tx := contract.Call(balanceContractAddr, "transferX",
|
tx := contract.Call(balanceContractAddr, "transferX",
|
||||||
|
contract.All,
|
||||||
from,
|
from,
|
||||||
to,
|
to,
|
||||||
containerFee,
|
containerFee,
|
||||||
|
@ -138,7 +139,7 @@ func Put(container, signature, publicKey []byte) bool {
|
||||||
|
|
||||||
addContainer(ctx, containerID, ownerID, container)
|
addContainer(ctx, containerID, ownerID, container)
|
||||||
// try to remove underscore at v0.92.0
|
// try to remove underscore at v0.92.0
|
||||||
_ = contract.Call(neofsIDContractAddr, "addKey", ownerID, [][]byte{publicKey})
|
_ = contract.Call(neofsIDContractAddr, "addKey", contract.All, ownerID, [][]byte{publicKey})
|
||||||
|
|
||||||
runtime.Log("put: added new container")
|
runtime.Log("put: added new container")
|
||||||
} else {
|
} else {
|
||||||
|
@ -163,7 +164,7 @@ func Delete(containerID, signature []byte) bool {
|
||||||
if len(irKey) == 0 {
|
if len(irKey) == 0 {
|
||||||
// check provided key
|
// check provided key
|
||||||
neofsIDContractAddr := storage.Get(ctx, neofsIDContractKey).([]byte)
|
neofsIDContractAddr := storage.Get(ctx, neofsIDContractKey).([]byte)
|
||||||
keys := contract.Call(neofsIDContractAddr, "key", ownerID).([][]byte)
|
keys := contract.Call(neofsIDContractAddr, "key", contract.ReadOnly, ownerID).([][]byte)
|
||||||
|
|
||||||
if !verifySignature(containerID, signature, keys) {
|
if !verifySignature(containerID, signature, keys) {
|
||||||
panic("delete: invalid owner signature")
|
panic("delete: invalid owner signature")
|
||||||
|
@ -232,7 +233,7 @@ func SetEACL(eACL, signature []byte) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
neofsIDContractAddr := storage.Get(ctx, neofsIDContractKey).([]byte)
|
neofsIDContractAddr := storage.Get(ctx, neofsIDContractKey).([]byte)
|
||||||
keys := contract.Call(neofsIDContractAddr, "key", ownerID).([][]byte)
|
keys := contract.Call(neofsIDContractAddr, "key", contract.ReadOnly, ownerID).([][]byte)
|
||||||
|
|
||||||
if !verifySignature(eACL, signature, keys) {
|
if !verifySignature(eACL, signature, keys) {
|
||||||
panic("setEACL: invalid eACL signature")
|
panic("setEACL: invalid eACL signature")
|
||||||
|
@ -266,7 +267,7 @@ func EACL(containerID []byte) extendedACL {
|
||||||
// attach corresponding public key if it was not revoked from neofs id
|
// attach corresponding public key if it was not revoked from neofs id
|
||||||
|
|
||||||
neofsIDContractAddr := storage.Get(ctx, neofsIDContractKey).([]byte)
|
neofsIDContractAddr := storage.Get(ctx, neofsIDContractKey).([]byte)
|
||||||
keys := contract.Call(neofsIDContractAddr, "key", ownerID).([][]byte)
|
keys := contract.Call(neofsIDContractAddr, "key", contract.ReadOnly, ownerID).([][]byte)
|
||||||
|
|
||||||
for i := range keys {
|
for i := range keys {
|
||||||
key := keys[i]
|
key := keys[i]
|
||||||
|
@ -560,7 +561,7 @@ func getContainerSizeEstimation(key, cid []byte) containerSizes {
|
||||||
// announce container size estimation of previous epoch.
|
// announce container size estimation of previous epoch.
|
||||||
func isStorageNode(key interop.PublicKey) bool {
|
func isStorageNode(key interop.PublicKey) bool {
|
||||||
netmapContractAddr := storage.Get(ctx, netmapContractKey).([]byte)
|
netmapContractAddr := storage.Get(ctx, netmapContractKey).([]byte)
|
||||||
snapshot := contract.Call(netmapContractAddr, "snapshot", 1).([]storageNode)
|
snapshot := contract.Call(netmapContractAddr, "snapshot", contract.ReadOnly, 1).([]storageNode)
|
||||||
|
|
||||||
for i := range snapshot {
|
for i := range snapshot {
|
||||||
nodeInfo := snapshot[i].info
|
nodeInfo := snapshot[i].info
|
||||||
|
|
|
@ -175,7 +175,7 @@ func InnerRingCandidateAdd(key []byte) bool {
|
||||||
fee := getConfig(ctx, candidateFeeConfigKey).(int)
|
fee := getConfig(ctx, candidateFeeConfigKey).(int)
|
||||||
|
|
||||||
transferred := contract.Call([]byte(tokenHash),
|
transferred := contract.Call([]byte(tokenHash),
|
||||||
"transfer", from, to, fee,
|
"transfer", contract.All, from, to, fee,
|
||||||
[]byte(ignoreDepositNotification)).(bool)
|
[]byte(ignoreDepositNotification)).(bool)
|
||||||
if !transferred {
|
if !transferred {
|
||||||
panic("irCandidateAdd: failed to transfer funds, aborting")
|
panic("irCandidateAdd: failed to transfer funds, aborting")
|
||||||
|
@ -231,7 +231,7 @@ func Deposit(from interop.Hash160, amount int, rcv interop.Hash160) bool {
|
||||||
to := runtime.GetExecutingScriptHash()
|
to := runtime.GetExecutingScriptHash()
|
||||||
|
|
||||||
transferred := contract.Call([]byte(tokenHash), "transfer",
|
transferred := contract.Call([]byte(tokenHash), "transfer",
|
||||||
from, to, amount, rcv).(bool)
|
contract.All, from, to, amount, rcv).(bool)
|
||||||
if !transferred {
|
if !transferred {
|
||||||
panic("deposit: failed to transfer funds, aborting")
|
panic("deposit: failed to transfer funds, aborting")
|
||||||
}
|
}
|
||||||
|
@ -289,7 +289,7 @@ func Cheque(id, user []byte, amount int, lockAcc []byte) bool {
|
||||||
from := runtime.GetExecutingScriptHash()
|
from := runtime.GetExecutingScriptHash()
|
||||||
|
|
||||||
transferred := contract.Call([]byte(tokenHash),
|
transferred := contract.Call([]byte(tokenHash),
|
||||||
"transfer", from, user, amount, nil).(bool)
|
"transfer", contract.All, from, user, amount, nil).(bool)
|
||||||
if !transferred {
|
if !transferred {
|
||||||
panic("cheque: failed to transfer funds, aborting")
|
panic("cheque: failed to transfer funds, aborting")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue