Use stint in wrc20 challenge

This commit is contained in:
Yuriy Glukhov 2018-08-10 18:12:18 +03:00
parent 7fb5a95ac4
commit 44aad38464
2 changed files with 11 additions and 5 deletions

View File

@ -6,7 +6,7 @@ skipDirs = @["examples"]
# Dependencies
requires "nim >= 0.18.1"
requires "nim >= 0.18.1", "stint"
proc buildExample(name: string) =
exec "nim c --out:examples/" & name & ".wasm examples/" & name

View File

@ -1,7 +1,7 @@
## ewasm “WRC20” token contract coding challenge
## https://gist.github.com/axic/16158c5c88fbc7b1d09dfa8c658bc363
import ../eth_contracts
import ../eth_contracts, stint
proc do_balance() =
if getCallDataSize() != 24:
@ -30,15 +30,21 @@ proc do_transfer() =
var recipientBalance: array[32, byte]
storageLoad(recipient, addr recipientBalance)
var sb = readUintBE[256](senderBalance)
var rb = readUintBE[256](recipientBalance)
let v = value.u256
block:
# This is a quick stub to avoid using stint for now. Works only with
# single byte values.
if sender_balance[31].uint64 < value:
if sb < v:
revert(nil, 0)
sender_balance[31] -= value.byte
recipient_balance[31] += value.byte
sb -= v
rb += v
senderBalance = sb.toByteArrayBE()
recipientBalance = rb.toByteArrayBE()
storageStore(sender, addr senderBalance)
storageStore(recipient, addr recipientBalance)