本文整理汇总了Golang中github.com/shiftcurrency/shift/core/state.StateDB.GetCode方法的典型用法代码示例。如果您正苦于以下问题:Golang StateDB.GetCode方法的具体用法?Golang StateDB.GetCode怎么用?Golang StateDB.GetCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/shiftcurrency/shift/core/state.StateDB
的用法示例。
在下文中一共展示了StateDB.GetCode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ValidatePostState
func (t *BlockTest) ValidatePostState(statedb *state.StateDB) error {
for addrString, acct := range t.preAccounts {
// XXX: is is worth it checking for errors here?
addr, err := hex.DecodeString(addrString)
if err != nil {
return err
}
code, err := hex.DecodeString(strings.TrimPrefix(acct.Code, "0x"))
if err != nil {
return err
}
balance, ok := new(big.Int).SetString(acct.Balance, 0)
if !ok {
return err
}
nonce, err := strconv.ParseUint(prepInt(16, acct.Nonce), 16, 64)
if err != nil {
return err
}
// address is indirectly verified by the other fields, as it's the db key
code2 := statedb.GetCode(common.BytesToAddress(addr))
balance2 := statedb.GetBalance(common.BytesToAddress(addr))
nonce2 := statedb.GetNonce(common.BytesToAddress(addr))
if !bytes.Equal(code2, code) {
return fmt.Errorf("account code mismatch, addr, found, expected: ", addrString, hex.EncodeToString(code2), hex.EncodeToString(code))
}
if balance2.Cmp(balance) != 0 {
return fmt.Errorf("account balance mismatch, addr, found, expected: ", addrString, balance2, balance)
}
if nonce2 != nonce {
return fmt.Errorf("account nonce mismatch, addr, found, expected: ", addrString, nonce2, nonce)
}
}
return nil
}