[#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:
Alex Vanin 2021-06-15 15:34:45 +03:00 committed by Alex Vanin
parent cb2559f590
commit a2c985ae4b

View file

@ -144,17 +144,20 @@ func Put(container []byte, signature interop.Signature, publicKey interop.Public
alphabetCall = runtime.CheckWitness(multiaddr) alphabetCall = runtime.CheckWitness(multiaddr)
} }
if !alphabetCall {
runtime.Notify("containerPut", container, signature, publicKey, token)
return
}
from := common.WalletToScriptHash(ownerID) from := common.WalletToScriptHash(ownerID)
netmapContractAddr := storage.Get(ctx, netmapContractKey).(interop.Hash160) netmapContractAddr := storage.Get(ctx, netmapContractKey).(interop.Hash160)
balanceContractAddr := storage.Get(ctx, balanceContractKey).(interop.Hash160) balanceContractAddr := storage.Get(ctx, balanceContractKey).(interop.Hash160)
containerFee := contract.Call(netmapContractAddr, "config", contract.ReadOnly, containerFeeKey).(int) containerFee := contract.Call(netmapContractAddr, "config", contract.ReadOnly, containerFeeKey).(int)
balance := contract.Call(balanceContractAddr, "balanceOf", contract.ReadOnly, from).(int)
details := common.ContainerFeeTransferDetails(containerID) 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 // todo: check if new container with unique container id
if notaryDisabled { if notaryDisabled {