• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang ethutil.NewValueFromBytes函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/ethereum/eth-go/ethutil.NewValueFromBytes函数的典型用法代码示例。如果您正苦于以下问题:Golang NewValueFromBytes函数的具体用法?Golang NewValueFromBytes怎么用?Golang NewValueFromBytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewValueFromBytes函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: getNode

func (t *Trie) getNode(node interface{}) *ethutil.Value {
	n := ethutil.NewValue(node)

	if !n.Get(0).IsNil() {
		return n
	}

	str := n.Str()
	if len(str) == 0 {
		return n
	} else if len(str) < 32 {
		return ethutil.NewValueFromBytes([]byte(str))
	}

	data := t.cache.Get(n.Bytes())

	return data
}
开发者ID:vmatekole,项目名称:eth-go,代码行数:18,代码来源:trie.go


示例17: ParseInput

func (i *Console) ParseInput(input string) bool {
	scanner := bufio.NewScanner(strings.NewReader(input))
	scanner.Split(bufio.ScanWords)

	count := 0
	var tokens []string
	for scanner.Scan() {
		count++
		tokens = append(tokens, scanner.Text())
	}
	if err := scanner.Err(); err != nil {
		fmt.Fprintln(os.Stderr, "reading input:", err)
	}

	if len(tokens) == 0 {
		return true
	}

	err := i.ValidateInput(tokens[0], count-1)
	if err != nil {
		fmt.Println(err)
	} else {
		switch tokens[0] {
		case "update":
			i.trie.Update(tokens[1], tokens[2])

			i.PrintRoot()
		case "get":
			fmt.Println(i.trie.Get(tokens[1]))
		case "root":
			i.PrintRoot()
		case "rawroot":
			fmt.Println(i.trie.Root)
		case "print":
			i.db.Print()
		case "dag":
			fmt.Println(ethchain.DaggerVerify(ethutil.Big(tokens[1]), // hash
				ethutil.BigPow(2, 36),   // diff
				ethutil.Big(tokens[2]))) // nonce
		case "decode":
			value := ethutil.NewValueFromBytes([]byte(tokens[1]))
			fmt.Println(value)
		case "getaddr":
			encoded, _ := hex.DecodeString(tokens[1])
			addr := i.ethereum.BlockManager.BlockChain().CurrentBlock.GetAddr(encoded)
			fmt.Println("addr:", addr)
		case "block":
			encoded, _ := hex.DecodeString(tokens[1])
			block := i.ethereum.BlockManager.BlockChain().GetBlock(encoded)
			fmt.Println(block)
		case "say":
			i.ethereum.Broadcast(ethwire.MsgTalkTy, []interface{}{tokens[1]})
		case "addp":
			i.ethereum.ConnectToPeer(tokens[1])
		case "pcount":
			fmt.Println("peers:", i.ethereum.Peers().Len())
		case "encode":
			fmt.Printf("%q\n", ethutil.Encode(tokens[1]))
		case "tx":
			recipient, err := hex.DecodeString(tokens[1])
			if err != nil {
				fmt.Println("recipient err:", err)
			} else {
				tx := ethchain.NewTransaction(recipient, ethutil.Big(tokens[2]), []string{""})
				data, _ := ethutil.Config.Db.Get([]byte("KeyRing"))
				keyRing := ethutil.NewValueFromBytes(data)
				tx.Sign(keyRing.Get(0).Bytes())
				fmt.Printf("%x\n", tx.Hash())
				i.ethereum.TxPool.QueueTransaction(tx)
			}

		case "gettx":
			addr, _ := hex.DecodeString(tokens[1])
			data, _ := ethutil.Config.Db.Get(addr)
			if len(data) != 0 {
				decoder := ethutil.NewValueFromBytes(data)
				fmt.Println(decoder)
			} else {
				fmt.Println("gettx: tx not found")
			}
		case "contract":
			contract := ethchain.NewTransaction([]byte{}, ethutil.Big(tokens[1]), []string{"PUSH", "1234"})
			fmt.Printf("%x\n", contract.Hash())

			i.ethereum.TxPool.QueueTransaction(contract)
		case "exit", "quit", "q":
			return false
		case "help":
			fmt.Printf("COMMANDS:\n" +
				"\033[1m= DB =\033[0m\n" +
				"update KEY VALUE - Updates/Creates a new value for the given key\n" +
				"get KEY - Retrieves the given key\n" +
				"root - Prints the hex encoded merkle root\n" +
				"rawroot - Prints the raw merkle root\n" +
				"block HASH - Prints the block\n" +
				"getaddr ADDR - Prints the account associated with the address\n" +
				"\033[1m= Dagger =\033[0m\n" +
				"dag HASH NONCE - Verifies a nonce with the given hash with dagger\n" +
				"\033[1m= Encoding =\033[0m\n" +
				"decode STR\n" +
//.........这里部分代码省略.........
开发者ID:kustomzone,项目名称:ether,代码行数:101,代码来源:dev_console.go


示例18: GetAddr

func (c *StateObject) GetAddr(addr []byte) *ethutil.Value {
	return ethutil.NewValueFromBytes([]byte(c.State.Trie.Get(string(addr))))
}
开发者ID:vmatekole,项目名称:eth-go,代码行数:3,代码来源:state_object.go


示例19: RlpDecode

func (tx *Transaction) RlpDecode(data []byte) {
	tx.RlpValueDecode(ethutil.NewValueFromBytes(data))
}
开发者ID:GrimDerp,项目名称:eth-go,代码行数:3,代码来源:transaction.go


示例20: Addr

func (c *Contract) Addr(addr []byte) *ethutil.Value {
	return ethutil.NewValueFromBytes([]byte(c.state.trie.Get(string(addr))))
}
开发者ID:GrimDerp,项目名称:eth-go,代码行数:3,代码来源:contract.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang ethutil.Value类代码示例发布时间:2022-05-23
下一篇:
Golang ethutil.NewValue函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap