本文整理匯總了Golang中github.com/ethereum/eth-go/ethutil.NewValueFromBytes函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewValueFromBytes函數的具體用法?Golang NewValueFromBytes怎麽用?Golang NewValueFromBytes使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewValueFromBytes函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Print
func (db *MemDatabase) Print() {
for key, val := range db.db {
fmt.Printf("%x(%d): ", key, len(key))
node := ethutil.NewValueFromBytes(val)
fmt.Printf("%q\n", node.Interface())
}
}
示例2: Get
// Returns the object stored at key and the type stored at key
// Returns nil if nothing is stored
func (s *State) Get(key []byte) (*ethutil.Value, ObjType) {
// Fetch data from the trie
data := s.trie.Get(string(key))
// Returns the nil type, indicating nothing could be retrieved.
// Anything using this function should check for this ret val
if data == "" {
return nil, NilTy
}
var typ ObjType
val := ethutil.NewValueFromBytes([]byte(data))
// Check the length of the retrieved value.
// Len 2 = Account
// Len 3 = Contract
// Other = invalid for now. If other types emerge, add them here
if val.Len() == 2 {
typ = AccountTy
} else if val.Len() == 3 {
typ = ContractTy
} else {
typ = UnknownTy
}
return val, typ
}
示例3: GetContract
func (s *State) GetContract(addr []byte) *Contract {
data := s.trie.Get(string(addr))
if data == "" {
return nil
}
// Whet get contract is called the retrieved value might
// be an account. The StateManager uses this to check
// to see if the address a tx was sent to is a contract
// or an account
value := ethutil.NewValueFromBytes([]byte(data))
if value.Len() == 2 {
return nil
}
// build contract
contract := NewContractFromBytes(addr, []byte(data))
// Check if there's a cached state for this contract
cachedState := s.states[string(addr)]
if cachedState != nil {
contract.state = cachedState
} else {
// If it isn't cached, cache the state
s.states[string(addr)] = contract.state
}
return contract
}
示例4: ReadMessage
func ReadMessage(data []byte) (msg *Msg, remaining []byte, done bool, err error) {
if len(data) == 0 {
return nil, nil, true, nil
}
if len(data) <= 8 {
return nil, remaining, false, errors.New("Invalid message")
}
// Check if the received 4 first bytes are the magic token
if bytes.Compare(MagicToken, data[:4]) != 0 {
return nil, nil, false, fmt.Errorf("MagicToken mismatch. Received %v", data[:4])
}
messageLength := ethutil.BytesToNumber(data[4:8])
remaining = data[8+messageLength:]
if int(messageLength) > len(data[8:]) {
return nil, nil, false, fmt.Errorf("message length %d, expected %d", len(data[8:]), messageLength)
}
message := data[8 : 8+messageLength]
decoder := ethutil.NewValueFromBytes(message)
// Type of message
t := decoder.Get(0).Uint()
// Actual data
d := decoder.SliceFrom(1)
msg = &Msg{
Type: MsgType(t),
Data: d,
}
return
}
示例5: RlpDecode
func (c *Contract) RlpDecode(data []byte) {
decoder := ethutil.NewValueFromBytes(data)
c.Amount = decoder.Get(0).BigInt()
c.Nonce = decoder.Get(1).Uint()
c.state = NewState(ethutil.NewTrie(ethutil.Config.Db, decoder.Get(2).Interface()))
}
示例6: GetInstr
func (c *StateObject) GetInstr(pc *big.Int) *ethutil.Value {
if int64(len(c.Code)-1) < pc.Int64() {
return ethutil.NewValue(0)
}
return ethutil.NewValueFromBytes([]byte{c.Code[pc.Int64()]})
}
示例7: RlpDecode
func (bi *BlockInfo) RlpDecode(data []byte) {
decoder := ethutil.NewValueFromBytes(data)
bi.Number = decoder.Get(0).Uint()
bi.Hash = decoder.Get(1).Bytes()
bi.Parent = decoder.Get(2).Bytes()
}
示例8: Print
func (db *LDBDatabase) Print() {
iter := db.db.NewIterator(nil, nil)
for iter.Next() {
key := iter.Key()
value := iter.Value()
fmt.Printf("%x(%d): ", key, len(key))
node := ethutil.NewValueFromBytes(value)
fmt.Printf("%v\n", node)
}
}
示例9: pushHandshake
func (p *Peer) pushHandshake() error {
data, _ := ethutil.Config.Db.Get([]byte("KeyRing"))
pubkey := ethutil.NewValueFromBytes(data).Get(2).Bytes()
msg := ethwire.NewMessage(ethwire.MsgHandshakeTy, []interface{}{
uint32(ProtocolVersion), uint32(0), p.Version, byte(p.caps), p.port, pubkey,
})
p.QueueMessage(msg)
return nil
}
示例10: NewKeyRingFromBytes
func NewKeyRingFromBytes(data []byte) (*KeyRing, error) {
var secrets [][]byte
it := ethutil.NewValueFromBytes(data).NewIterator()
for it.Next() {
secret := it.Value().Bytes()
secrets = append(secrets, secret)
}
keyRing, err := NewKeyRingFromSecrets(secrets)
if err != nil {
return nil, err
}
return keyRing, nil
}
示例11: RlpDecode
func (c *StateObject) RlpDecode(data []byte) {
decoder := ethutil.NewValueFromBytes(data)
c.Nonce = decoder.Get(0).Uint()
c.Balance = decoder.Get(1).BigInt()
c.State = New(ethtrie.New(ethutil.Config.Db, decoder.Get(2).Interface()))
c.storage = make(map[string]*ethutil.Value)
c.gasPool = new(big.Int)
c.CodeHash = decoder.Get(3).Bytes()
c.Code, _ = ethutil.Config.Db.Get(c.CodeHash)
}
示例12: GetKeyRing
func GetKeyRing(state *State) *KeyRing {
if keyRing == nil {
keyRing = &KeyRing{}
data, _ := ethutil.Config.Db.Get([]byte("KeyRing"))
it := ethutil.NewValueFromBytes(data).NewIterator()
for it.Next() {
v := it.Value()
keyRing.Add(NewKeyPairFromValue(v))
}
}
return keyRing
}
示例13: contractMemory
// Returns an address from the specified contract's address
func contractMemory(state *State, contractAddr []byte, memAddr *big.Int) *big.Int {
contract := state.GetContract(contractAddr)
if contract == nil {
log.Panicf("invalid contract addr %x", contractAddr)
}
val := state.trie.Get(memAddr.String())
// decode the object as a big integer
decoder := ethutil.NewValueFromBytes([]byte(val))
if decoder.IsNil() {
return ethutil.BigFalse
}
return decoder.BigInt()
}
示例14: Get
func (cache *Cache) Get(key []byte) *ethutil.Value {
// First check if the key is the cache
if cache.nodes[string(key)] != nil {
return cache.nodes[string(key)].Value
}
// Get the key of the database instead and cache it
data, _ := cache.db.Get(key)
// Create the cached value
value := ethutil.NewValueFromBytes(data)
// Create caching node
cache.nodes[string(key)] = NewNode(key, value, false)
return value
}
示例15: NewPeer
func NewPeer(conn net.Conn, ethereum *Ethereum, inbound bool) *Peer {
data, _ := ethutil.Config.Db.Get([]byte("KeyRing"))
pubkey := ethutil.NewValueFromBytes(data).Get(2).Bytes()
return &Peer{
outputQueue: make(chan *ethwire.Msg, outputBufferSize),
quit: make(chan bool),
ethereum: ethereum,
conn: conn,
inbound: inbound,
disconnect: 0,
connected: 1,
port: 30303,
pubkey: pubkey,
}
}