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

Golang common.CopyBytes函数代码示例

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

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



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

示例1: Put

func (b *memBatch) Put(key, value []byte) error {
	b.lock.Lock()
	defer b.lock.Unlock()

	b.writes = append(b.writes, kv{common.CopyBytes(key), common.CopyBytes(value)})
	return nil
}
开发者ID:expanse-project,项目名称:go-expanse,代码行数:7,代码来源:memory_database.go


示例2: TestReset

func TestReset(t *testing.T) {
	trie := NewEmpty()
	vals := []struct{ k, v string }{
		{"do", "verb"},
		{"expanse", "wookiedoo"},
		{"horse", "stallion"},
	}
	for _, val := range vals {
		trie.UpdateString(val.k, val.v)
	}
	trie.Commit()

	before := common.CopyBytes(trie.roothash)
	trie.UpdateString("should", "revert")
	trie.Hash()
	// Should have no effect
	trie.Hash()
	trie.Hash()
	// ###

	trie.Reset()
	after := common.CopyBytes(trie.roothash)

	if !bytes.Equal(before, after) {
		t.Errorf("expected roots to be equal. %x - %x", before, after)
	}
}
开发者ID:este-xx,项目名称:go-expanse,代码行数:27,代码来源:trie_test.go


示例3: Copy

func (self *StateObject) Copy() *StateObject {
	stateObject := NewStateObject(self.Address(), self.db)
	stateObject.balance.Set(self.balance)
	stateObject.codeHash = common.CopyBytes(self.codeHash)
	stateObject.nonce = self.nonce
	stateObject.trie = self.trie
	stateObject.code = common.CopyBytes(self.code)
	stateObject.initCode = common.CopyBytes(self.initCode)
	stateObject.storage = self.storage.Copy()
	stateObject.remove = self.remove
	stateObject.dirty = self.dirty
	stateObject.deleted = self.deleted

	return stateObject
}
开发者ID:5mil,项目名称:go-expanse,代码行数:15,代码来源:state_object.go


示例4: NewTransaction

func NewTransaction(nonce uint64, to common.Address, amount, gasLimit, gasPrice *big.Int, data []byte) *Transaction {
	if len(data) > 0 {
		data = common.CopyBytes(data)
	}
	d := txdata{
		AccountNonce: nonce,
		Recipient:    &to,
		Payload:      data,
		Amount:       new(big.Int),
		GasLimit:     new(big.Int),
		Price:        new(big.Int),
		R:            new(big.Int),
		S:            new(big.Int),
	}
	if amount != nil {
		d.Amount.Set(amount)
	}
	if gasLimit != nil {
		d.GasLimit.Set(gasLimit)
	}
	if gasPrice != nil {
		d.Price.Set(gasPrice)
	}
	return &Transaction{data: d}
}
开发者ID:expanse-project,项目名称:go-expanse,代码行数:25,代码来源:transaction.go


示例5: Put

func (db *MemDatabase) Put(key []byte, value []byte) error {
	db.lock.Lock()
	defer db.lock.Unlock()

	db.db[string(key)] = common.CopyBytes(value)
	return nil
}
开发者ID:Cisko-Rijken,项目名称:go-expanse,代码行数:7,代码来源:memory_database.go


示例6: TryUpdate

// TryUpdate associates key with value in the trie. Subsequent calls to
// Get will return value. If value has length zero, any existing value
// is deleted from the trie and calls to Get will return nil.
//
// The value bytes must not be modified by the caller while they are
// stored in the trie.
//
// If a node was not found in the database, a MissingNodeError is returned.
func (t *SecureTrie) TryUpdate(key, value []byte) error {
	hk := t.hashKey(key)
	err := t.trie.TryUpdate(hk, value)
	if err != nil {
		return err
	}
	t.getSecKeyCache()[string(hk)] = common.CopyBytes(key)
	return nil
}
开发者ID:expanse-project,项目名称:go-expanse,代码行数:17,代码来源:secure_trie.go


示例7: NewContractCreation

func NewContractCreation(nonce uint64, amount, gasLimit, gasPrice *big.Int, data []byte) *Transaction {
	if len(data) > 0 {
		data = common.CopyBytes(data)
	}
	return &Transaction{data: txdata{
		AccountNonce: nonce,
		Recipient:    nil,
		Amount:       new(big.Int).Set(amount),
		GasLimit:     new(big.Int).Set(gasLimit),
		Price:        new(big.Int).Set(gasPrice),
		Payload:      data,
		R:            new(big.Int),
		S:            new(big.Int),
	}}
}
开发者ID:expanse-project,项目名称:go-expanse,代码行数:15,代码来源:transaction.go


示例8: hashChildren

// hashChildren replaces the children of a node with their hashes if the encoded
// size of the child is larger than a hash, returning the collapsed node as well
// as a replacement for the original node with the child hashes cached in.
func (h *hasher) hashChildren(original node, db DatabaseWriter) (node, node, error) {
	var err error

	switch n := original.(type) {
	case shortNode:
		// Hash the short node's child, caching the newly hashed subtree
		cached := n
		cached.Key = common.CopyBytes(cached.Key)

		n.Key = compactEncode(n.Key)
		if _, ok := n.Val.(valueNode); !ok {
			if n.Val, cached.Val, err = h.hash(n.Val, db, false); err != nil {
				return n, original, err
			}
		}
		if n.Val == nil {
			n.Val = valueNode(nil) // Ensure that nil children are encoded as empty strings.
		}
		return n, cached, nil

	case fullNode:
		// Hash the full node's children, caching the newly hashed subtrees
		cached := fullNode{dirty: n.dirty}

		for i := 0; i < 16; i++ {
			if n.Children[i] != nil {
				if n.Children[i], cached.Children[i], err = h.hash(n.Children[i], db, false); err != nil {
					return n, original, err
				}
			} else {
				n.Children[i] = valueNode(nil) // Ensure that nil children are encoded as empty strings.
			}
		}
		cached.Children[16] = n.Children[16]
		if n.Children[16] == nil {
			n.Children[16] = valueNode(nil)
		}
		return n, cached, nil

	default:
		// Value and hash nodes don't have children so they're left as were
		return n, original, nil
	}
}
开发者ID:expanse-project,项目名称:go-expanse,代码行数:47,代码来源:hasher.go


示例9: Data

func (tx *Transaction) Data() []byte       { return common.CopyBytes(tx.data.Payload) }
开发者ID:expanse-project,项目名称:go-expanse,代码行数:1,代码来源:transaction.go


示例10: Copy

func (self *HashNode) Copy(t *Trie) Node { return NewHash(common.CopyBytes(self.key), t) }
开发者ID:este-xx,项目名称:go-expanse,代码行数:1,代码来源:hashnode.go


示例11: NewReceipt

// NewReceipt creates a barebone transaction receipt, copying the init fields.
func NewReceipt(root []byte, cumulativeGasUsed *big.Int) *Receipt {
	return &Receipt{PostState: common.CopyBytes(root), CumulativeGasUsed: new(big.Int).Set(cumulativeGasUsed)}
}
开发者ID:Cisko-Rijken,项目名称:go-expanse,代码行数:4,代码来源:receipt.go


示例12: Copy

func (self *ShortNode) Copy(t *Trie) Node {
	node := &ShortNode{t, nil, self.value.Copy(t), self.dirty}
	node.key = common.CopyBytes(self.key)
	node.dirty = true
	return node
}
开发者ID:este-xx,项目名称:go-expanse,代码行数:6,代码来源:shortnode.go


示例13: Extra

func (b *Block) Extra() []byte            { return common.CopyBytes(b.header.Extra) }
开发者ID:este-xx,项目名称:go-expanse,代码行数:1,代码来源:block.go


示例14: Copy

func (self *ValueNode) Copy(t *Trie) Node {
	return &ValueNode{t, common.CopyBytes(self.data), self.dirty}
}
开发者ID:este-xx,项目名称:go-expanse,代码行数:3,代码来源:valuenode.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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