mirror of
https://github.com/status-im/nim-eth-contracts.git
synced 2025-03-01 19:10:39 +00:00
Use stint in wrc20 challenge
This commit is contained in:
parent
7fb5a95ac4
commit
44aad38464
@ -6,7 +6,7 @@ skipDirs = @["examples"]
|
|||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
|
||||||
requires "nim >= 0.18.1"
|
requires "nim >= 0.18.1", "stint"
|
||||||
|
|
||||||
proc buildExample(name: string) =
|
proc buildExample(name: string) =
|
||||||
exec "nim c --out:examples/" & name & ".wasm examples/" & name
|
exec "nim c --out:examples/" & name & ".wasm examples/" & name
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
## ewasm “WRC20” token contract coding challenge
|
## ewasm “WRC20” token contract coding challenge
|
||||||
## https://gist.github.com/axic/16158c5c88fbc7b1d09dfa8c658bc363
|
## https://gist.github.com/axic/16158c5c88fbc7b1d09dfa8c658bc363
|
||||||
|
|
||||||
import ../eth_contracts
|
import ../eth_contracts, stint
|
||||||
|
|
||||||
proc do_balance() =
|
proc do_balance() =
|
||||||
if getCallDataSize() != 24:
|
if getCallDataSize() != 24:
|
||||||
@ -30,15 +30,21 @@ proc do_transfer() =
|
|||||||
var recipientBalance: array[32, byte]
|
var recipientBalance: array[32, byte]
|
||||||
storageLoad(recipient, addr recipientBalance)
|
storageLoad(recipient, addr recipientBalance)
|
||||||
|
|
||||||
|
var sb = readUintBE[256](senderBalance)
|
||||||
|
var rb = readUintBE[256](recipientBalance)
|
||||||
|
let v = value.u256
|
||||||
|
|
||||||
block:
|
block:
|
||||||
# This is a quick stub to avoid using stint for now. Works only with
|
# This is a quick stub to avoid using stint for now. Works only with
|
||||||
# single byte values.
|
# single byte values.
|
||||||
if sender_balance[31].uint64 < value:
|
if sb < v:
|
||||||
revert(nil, 0)
|
revert(nil, 0)
|
||||||
|
|
||||||
sender_balance[31] -= value.byte
|
sb -= v
|
||||||
recipient_balance[31] += value.byte
|
rb += v
|
||||||
|
|
||||||
|
senderBalance = sb.toByteArrayBE()
|
||||||
|
recipientBalance = rb.toByteArrayBE()
|
||||||
storageStore(sender, addr senderBalance)
|
storageStore(sender, addr senderBalance)
|
||||||
storageStore(recipient, addr recipientBalance)
|
storageStore(recipient, addr recipientBalance)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user