diff --git a/code/go/0chain.net/smartcontract/storagesc/writepool.go b/code/go/0chain.net/smartcontract/storagesc/writepool.go index f8397dd657..6b2b7c57ea 100644 --- a/code/go/0chain.net/smartcontract/storagesc/writepool.go +++ b/code/go/0chain.net/smartcontract/storagesc/writepool.go @@ -2,6 +2,7 @@ package storagesc import ( "encoding/json" + "fmt" cstate "0chain.net/chaincore/chain/state" "0chain.net/chaincore/state" @@ -80,21 +81,27 @@ func (ssc *StorageSmartContract) writePoolLock( } if allocation.Finalized || allocation.Canceled { - return "", common.NewError("write_pool_unlock_failed", + return "", common.NewError("write_pool_lock_failed", "can't lock tokens with a finalized or cancelled allocation") } allocation.WritePool, err = currency.AddCoin(allocation.WritePool, txn.Value) - i, _ := txn.Value.Int64() + if err != nil { + return "", common.NewError("write_pool_lock_failed", fmt.Sprintf("write pool token overflow: %v", err)) + } + + i, err := txn.Value.Int64() + if err != nil { + return "", common.NewError("write_pool_lock_failed", fmt.Sprintf("invalid lock value: %v", err)) + } + balances.EmitEvent(event.TypeStats, event.TagLockWritePool, allocation.ID, event.WritePoolLock{ Client: txn.ClientID, AllocationId: allocation.ID, Amount: i, }) - if err != nil { - return "", common.NewError("write_pool_unlock_failed", err.Error()) - } + if err := allocation.saveUpdatedStakes(balances); err != nil { return "", common.NewError("write_pool_lock_failed", err.Error()) }