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

Golang ethutil.NewValue函数代码示例

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

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



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

示例1: Gets

func (c *Closure) Gets(x, y *big.Int) *ethutil.Value {
	if x.Int64() >= int64(len(c.Code)) || y.Int64() >= int64(len(c.Code)) {
		return ethutil.NewValue(0)
	}

	partial := c.Code[x.Int64() : x.Int64()+y.Int64()]

	return ethutil.NewValue(partial)
}
开发者ID:vmatekole,项目名称:eth-go,代码行数:9,代码来源:closure.go


示例2: ParanoiaCheck

func ParanoiaCheck(t1 *Trie) (bool, *Trie) {
	t2 := New(ethutil.Config.Db, "")

	t1.NewIterator().Each(func(key string, v *ethutil.Value) {
		t2.Update(key, v.Str())
	})

	a := ethutil.NewValue(t2.Root).Bytes()
	b := ethutil.NewValue(t1.Root).Bytes()

	return bytes.Compare(a, b) == 0, t2
}
开发者ID:vmatekole,项目名称:eth-go,代码行数:12,代码来源:trie.go


示例3: 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


示例4: Write

// Write to the Ethereum network specifying the type of the message and
// the data. Data can be of type RlpEncodable or []interface{}. Returns
// nil or if something went wrong an error.
func (self *Connection) Write(typ MsgType, v ...interface{}) error {
	var pack []byte

	slice := [][]interface{}{[]interface{}{byte(typ)}}
	for _, value := range v {
		if encodable, ok := value.(ethutil.RlpEncodeDecode); ok {
			slice = append(slice, encodable.RlpValue())
		} else if raw, ok := value.([]interface{}); ok {
			slice = append(slice, raw)
		} else {
			panic(fmt.Sprintf("Unable to 'write' object of type %T", value))
		}
	}

	// Encode the type and the (RLP encoded) data for sending over the wire
	encoded := ethutil.NewValue(slice).Encode()
	payloadLength := ethutil.NumberToBytes(uint32(len(encoded)), 32)

	// Write magic token and payload length (first 8 bytes)
	pack = append(MagicToken, payloadLength...)
	pack = append(pack, encoded...)

	// Write to the connection
	_, err := self.conn.Write(pack)
	if err != nil {
		return err
	}

	return nil
}
开发者ID:vmatekole,项目名称:eth-go,代码行数:33,代码来源:messaging.go


示例5: getState

func (t *Trie) getState(node interface{}, key []int) interface{} {
	n := ethutil.NewValue(node)
	// Return the node if key is empty (= found)
	if len(key) == 0 || n.IsNil() || n.Len() == 0 {
		return node
	}

	currentNode := t.getNode(node)
	length := currentNode.Len()

	if length == 0 {
		return ""
	} else if length == 2 {
		// Decode the key
		k := CompactDecode(currentNode.Get(0).Str())
		v := currentNode.Get(1).Raw()

		if len(key) >= len(k) && CompareIntSlice(k, key[:len(k)]) {
			return t.getState(v, key[len(k):])
		} else {
			return ""
		}
	} else if length == 17 {
		return t.getState(currentNode.Get(key[0]).Raw(), key[1:])
	}

	// It shouldn't come this far
	panic("unexpected return")
}
开发者ID:vmatekole,项目名称:eth-go,代码行数:29,代码来源:trie.go


示例6: TestRun2

func TestRun2(t *testing.T) {
	ethutil.ReadConfig("")

	db, _ := ethdb.NewMemDatabase()
	state := NewState(ethutil.NewTrie(db, ""))

	script := Compile([]string{
		"PUSH", "0",
		"PUSH", "0",
		"TXSENDER",
		"PUSH", "10000000",
		"MKTX",
	})
	fmt.Println(ethutil.NewValue(script))

	tx := NewTransaction(ContractAddr, ethutil.Big("100000000000000000000000000000000000000000000000000"), script)
	fmt.Printf("contract addr %x\n", tx.Hash()[12:])
	contract := MakeContract(tx, state)
	vm := &Vm{}

	vm.Process(contract, state, RuntimeVars{
		address:     tx.Hash()[12:],
		blockNumber: 1,
		sender:      ethutil.FromHex("cd1722f3947def4cf144679da39c4c32bdc35681"),
		prevHash:    ethutil.FromHex("5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"),
		coinbase:    ethutil.FromHex("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"),
		time:        1,
		diff:        big.NewInt(256),
		txValue:     tx.Value,
		txData:      tx.Data,
	})
}
开发者ID:GrimDerp,项目名称:eth-go,代码行数:32,代码来源:vm_test.go


示例7: PrintRoot

func (i *Console) PrintRoot() {
	root := ethutil.NewValue(i.trie.Root)
	if len(root.Bytes()) != 0 {
		fmt.Println(hex.EncodeToString(root.Bytes()))
	} else {
		fmt.Println(i.trie.Root)
	}
}
开发者ID:kustomzone,项目名称:ether,代码行数:8,代码来源:dev_console.go


示例8: CreateTxSha

func CreateTxSha(receipts Receipts) (sha []byte) {
	trie := ethtrie.New(ethutil.Config.Db, "")
	for i, receipt := range receipts {
		trie.Update(string(ethutil.NewValue(i).Encode()), string(ethutil.NewValue(receipt.RlpData()).Encode()))
	}

	switch trie.Root.(type) {
	case string:
		sha = []byte(trie.Root.(string))
	case []byte:
		sha = trie.Root.([]byte)
	default:
		panic(fmt.Sprintf("invalid root type %T", trie.Root))
	}

	return sha
}
开发者ID:vmatekole,项目名称:eth-go,代码行数:17,代码来源:block.go


示例9: Collect

func (it *TrieIterator) Collect() [][]byte {
	if it.trie.Root == "" {
		return nil
	}

	it.getNode(ethutil.NewValue(it.trie.Root).Bytes())

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


示例10: Get

func (t *Trie) Get(key string) string {
	t.mut.RLock()
	defer t.mut.RUnlock()

	k := CompactHexDecode(key)
	c := ethutil.NewValue(t.getState(t.Root, k))

	return c.Str()
}
开发者ID:vmatekole,项目名称:eth-go,代码行数:9,代码来源:trie.go


示例11: CompileToValues

func CompileToValues(code []string) (script []*ethutil.Value) {
	script = make([]*ethutil.Value, len(code))
	for i, val := range code {
		instr, _ := ethutil.CompileInstr(val)

		script[i] = ethutil.NewValue(instr)
	}

	return
}
开发者ID:josephyzhou,项目名称:eth-go,代码行数:10,代码来源:state.go


示例12: SetEarliestBlock

// Set the earliest and latest block for filtering.
// -1 = latest block (i.e., the current block)
// hash = particular hash from-to
func (self *Filter) SetEarliestBlock(earliest interface{}) {
	e := ethutil.NewValue(earliest)

	// Check for -1 (latest) otherwise assume bytes
	if e.Int() == -1 {
		self.earliest = self.eth.BlockChain().CurrentBlock.Hash()
	} else if e.Len() > 0 {
		self.earliest = e.Bytes()
	} else {
		panic(fmt.Sprintf("earliest has to be either -1 or a valid hash: %v (%T)", e, e.Val))
	}
}
开发者ID:vmatekole,项目名称:eth-go,代码行数:15,代码来源:filter.go


示例13: SetLatestBlock

func (self *Filter) SetLatestBlock(latest interface{}) {
	l := ethutil.NewValue(latest)

	// Check for -1 (latest) otherwise assume bytes
	if l.Int() == -1 {
		self.latest = self.eth.BlockChain().CurrentBlock.Hash()
	} else if l.Len() > 0 {
		self.latest = l.Bytes()
	} else {
		panic(fmt.Sprintf("latest has to be either -1 or a valid hash: %v", l))
	}
}
开发者ID:vmatekole,项目名称:eth-go,代码行数:12,代码来源:filter.go


示例14: TestSnapshot

func TestSnapshot(t *testing.T) {
	db, _ := ethdb.NewMemDatabase()
	ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "")
	ethutil.Config.Db = db

	state := New(ethtrie.New(db, ""))

	stateObject := state.GetOrNewStateObject([]byte("aa"))

	stateObject.SetStorage(ethutil.Big("0"), ethutil.NewValue(42))

	snapshot := state.Copy()

	stateObject = state.GetStateObject([]byte("aa"))
	stateObject.SetStorage(ethutil.Big("0"), ethutil.NewValue(43))

	state.Set(snapshot)

	stateObject = state.GetStateObject([]byte("aa"))
	res := stateObject.GetStorage(ethutil.Big("0"))
	if !res.Cmp(ethutil.NewValue(42)) {
		t.Error("Expected storage 0 to be 42", res)
	}
}
开发者ID:vmatekole,项目名称:eth-go,代码行数:24,代码来源:state_test.go


示例15: PutValue

func (cache *Cache) PutValue(v interface{}, force bool) interface{} {
	value := ethutil.NewValue(v)

	enc := value.Encode()
	if len(enc) >= 32 || force {
		sha := ethcrypto.Sha3Bin(enc)

		cache.nodes[string(sha)] = NewNode(sha, value, true)
		cache.IsDirty = true

		return sha
	}

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


示例16: EachStorage

// Iterate over each storage address and yield callback
func (self *StateObject) EachStorage(cb ethtrie.EachCallback) {
	// First loop over the uncommit/cached values in storage
	for key, value := range self.storage {
		// XXX Most iterators Fns as it stands require encoded values
		encoded := ethutil.NewValue(value.Encode())
		cb(key, encoded)
	}

	it := self.State.Trie.NewIterator()
	it.Each(func(key string, value *ethutil.Value) {
		// If it's cached don't call the callback.
		if self.storage[key] == nil {
			cb(key, value)
		}
	})
}
开发者ID:vmatekole,项目名称:eth-go,代码行数:17,代码来源:state_object.go


示例17: 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


示例18: WriteMessage

// The basic message writer takes care of writing data over the given
// connection and does some basic error checking
func WriteMessage(conn net.Conn, msg *Msg) error {
	var pack []byte

	// Encode the type and the (RLP encoded) data for sending over the wire
	encoded := ethutil.NewValue(append([]interface{}{byte(msg.Type)}, msg.Data.Slice()...)).Encode()
	payloadLength := ethutil.NumberToBytes(uint32(len(encoded)), 32)

	// Write magic token and payload length (first 8 bytes)
	pack = append(MagicToken, payloadLength...)
	pack = append(pack, encoded...)
	//fmt.Printf("payload %v (%v) %q\n", msg.Type, conn.RemoteAddr(), encoded)

	// Write to the connection
	_, err := conn.Write(pack)
	if err != nil {
		return err
	}

	return nil
}
开发者ID:josephyzhou,项目名称:eth-go,代码行数:22,代码来源:messaging.go


示例19: TestNew

func TestNew(t *testing.T) {
	pipe := New(nil)

	var addr, privy, recp, data []byte
	var object *ethstate.StateObject
	var key *ethcrypto.KeyPair

	world := pipe.World()
	world.Get(addr)
	world.Coinbase()
	world.IsMining()
	world.IsListening()
	world.State()
	peers := world.Peers()
	peers.Len()

	// Shortcut functions
	pipe.Balance(addr)
	pipe.Nonce(addr)
	pipe.Block(addr)
	pipe.Storage(addr, addr)
	pipe.ToAddress(privy)
	pipe.Exists(addr)
	// Doesn't change state
	pipe.Execute(addr, nil, Val(0), Val(1000000), Val(10))
	// Doesn't change state
	pipe.ExecuteObject(object, nil, Val(0), Val(1000000), Val(10))

	conf := world.Config()
	namereg := conf.Get("NameReg")
	namereg.Storage(addr)

	var err error
	// Transact
	err = pipe.Transact(key, recp, ethutil.NewValue(0), ethutil.NewValue(0), ethutil.NewValue(0), nil)
	if err != nil {
		t.Error(err)
	}
	// Create
	err = pipe.Transact(key, nil, ethutil.NewValue(0), ethutil.NewValue(0), ethutil.NewValue(0), data)
	if err != nil {
		t.Error(err)
	}
}
开发者ID:vmatekole,项目名称:eth-go,代码行数:44,代码来源:pipe_test.go


示例20: CreateKeyPair

func CreateKeyPair(force bool) {
	data, _ := ethutil.Config.Db.Get([]byte("KeyRing"))
	if len(data) == 0 || force {
		pub, prv := secp256k1.GenerateKeyPair()
		addr := ethutil.Sha3Bin(pub[1:])[12:]

		fmt.Printf(`
Generating new address and keypair.
Please keep your keys somewhere save.
Currently Ethereum(G) does not support
exporting keys.

++++++++++++++++ KeyRing +++++++++++++++++++
addr: %x
prvk: %x
pubk: %x
++++++++++++++++++++++++++++++++++++++++++++

`, addr, prv, pub)

		keyRing := ethutil.NewValue([]interface{}{prv, addr, pub[1:]})
		ethutil.Config.Db.Put([]byte("KeyRing"), keyRing.Encode())
	}
}
开发者ID:kustomzone,项目名称:ether,代码行数:24,代码来源:ethereum.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang ethutil.NewValueFromBytes函数代码示例发布时间:2022-05-23
下一篇:
Golang ethutil.Hex2Bytes函数代码示例发布时间: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