[#92] container: Add balance check before new container notification
Balance check at container.Put command will drop some invalid transactions from the side chain network before inner ring approval. Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
cb2559f590
commit
a2c985ae4b
1 changed files with 8 additions and 5 deletions
|
@ -144,17 +144,20 @@ func Put(container []byte, signature interop.Signature, publicKey interop.Public
|
|||
alphabetCall = runtime.CheckWitness(multiaddr)
|
||||
}
|
||||
|
||||
if !alphabetCall {
|
||||
runtime.Notify("containerPut", container, signature, publicKey, token)
|
||||
return
|
||||
}
|
||||
|
||||
from := common.WalletToScriptHash(ownerID)
|
||||
netmapContractAddr := storage.Get(ctx, netmapContractKey).(interop.Hash160)
|
||||
balanceContractAddr := storage.Get(ctx, balanceContractKey).(interop.Hash160)
|
||||
containerFee := contract.Call(netmapContractAddr, "config", contract.ReadOnly, containerFeeKey).(int)
|
||||
balance := contract.Call(balanceContractAddr, "balanceOf", contract.ReadOnly, from).(int)
|
||||
details := common.ContainerFeeTransferDetails(containerID)
|
||||
|
||||
if !alphabetCall {
|
||||
if balance < containerFee*len(alphabet) {
|
||||
panic("insufficient balance to create container")
|
||||
}
|
||||
runtime.Notify("containerPut", container, signature, publicKey, token)
|
||||
return
|
||||
}
|
||||
// todo: check if new container with unique container id
|
||||
|
||||
if notaryDisabled {
|
||||
|
|
Loading…
Reference in a new issue