mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-04 09:02:28 +00:00
core: fix Storage.Get to return Null when there is no value
Match C# implementation and fix state inconsistency at block 249920 of preview2 testnet. Make our Go Storage.Get return nil and adapt examples/tests.
This commit is contained in:
parent
954c8ff8d6
commit
d81d826bfc
9 changed files with 67 additions and 30 deletions
18
pkg/rpc/server/testdata/test_contract.go
vendored
18
pkg/rpc/server/testdata/test_contract.go
vendored
|
@ -32,7 +32,11 @@ func Main(operation string, args []interface{}) interface{} {
|
|||
runtime.Log("invalid address")
|
||||
return false
|
||||
}
|
||||
amount := storage.Get(ctx, addr).(int)
|
||||
var amount int
|
||||
val := storage.Get(ctx, addr)
|
||||
if val != nil {
|
||||
amount = val.(int)
|
||||
}
|
||||
runtime.Notify("balanceOf", addr, amount)
|
||||
return amount
|
||||
case "transfer":
|
||||
|
@ -53,7 +57,11 @@ func Main(operation string, args []interface{}) interface{} {
|
|||
return false
|
||||
}
|
||||
|
||||
fromBalance := storage.Get(ctx, from).(int)
|
||||
var fromBalance int
|
||||
val := storage.Get(ctx, from)
|
||||
if val != nil {
|
||||
fromBalance = val.(int)
|
||||
}
|
||||
if fromBalance < amount {
|
||||
runtime.Log("insufficient funds")
|
||||
return false
|
||||
|
@ -61,7 +69,11 @@ func Main(operation string, args []interface{}) interface{} {
|
|||
fromBalance -= amount
|
||||
storage.Put(ctx, from, fromBalance)
|
||||
|
||||
toBalance := storage.Get(ctx, to).(int)
|
||||
var toBalance int
|
||||
val = storage.Get(ctx, to)
|
||||
if val != nil {
|
||||
toBalance = val.(int)
|
||||
}
|
||||
toBalance += amount
|
||||
storage.Put(ctx, to, toBalance)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue