当前位置: 首页>>代码示例>>Golang>>正文


Golang ethutil.NewValueFromBytes函数代码示例

本文整理汇总了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())
	}
}
开发者ID:vmatekole,项目名称:eth-go,代码行数:7,代码来源:memory_database.go

示例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
}
开发者ID:josephyzhou,项目名称:eth-go,代码行数:27,代码来源:state.go

示例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
}
开发者ID:josephyzhou,项目名称:eth-go,代码行数:29,代码来源:state.go

示例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
}
开发者ID:josephyzhou,项目名称:eth-go,代码行数:34,代码来源:messaging.go

示例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()))
}
开发者ID:GrimDerp,项目名称:eth-go,代码行数:7,代码来源:contract.go

示例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()]})
}
开发者ID:vmatekole,项目名称:eth-go,代码行数:7,代码来源:state_object.go

示例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()
}
开发者ID:GrimDerp,项目名称:eth-go,代码行数:7,代码来源:block.go

示例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)
	}
}
开发者ID:vmatekole,项目名称:eth-go,代码行数:11,代码来源:database.go

示例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
}
开发者ID:GrimDerp,项目名称:eth-go,代码行数:12,代码来源:peer.go

示例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
}
开发者ID:vmatekole,项目名称:eth-go,代码行数:13,代码来源:keyring.go

示例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)
}
开发者ID:vmatekole,项目名称:eth-go,代码行数:13,代码来源:state_object.go

示例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
}
开发者ID:josephyzhou,项目名称:eth-go,代码行数:14,代码来源:keypair.go

示例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()
}
开发者ID:GrimDerp,项目名称:eth-go,代码行数:16,代码来源:vm.go

示例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
}
开发者ID:vmatekole,项目名称:eth-go,代码行数:15,代码来源:trie.go

示例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,
	}
}
开发者ID:GrimDerp,项目名称:eth-go,代码行数:16,代码来源:peer.go


注:本文中的github.com/ethereum/eth-go/ethutil.NewValueFromBytes函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。