本文整理匯總了Golang中github.com/ethereum/eth-go/ethutil.NewValue函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewValue函數的具體用法?Golang NewValue怎麽用?Golang NewValue使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewValue函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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)
}
示例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
}
示例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()]})
}
示例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
}
示例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")
}
示例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,
})
}
示例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)
}
}
示例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
}
示例9: Collect
func (it *TrieIterator) Collect() [][]byte {
if it.trie.Root == "" {
return nil
}
it.getNode(ethutil.NewValue(it.trie.Root).Bytes())
return it.shas
}
示例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()
}
示例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
}
示例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))
}
}
示例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))
}
}
示例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)
}
}
示例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
}