func unpackAddr(value *ethutil.Value, p uint64) string { a := strconv.Itoa(int(value.Get(0).Uint())) b := strconv.Itoa(int(value.Get(1).Uint())) c := strconv.Itoa(int(value.Get(2).Uint())) d := strconv.Itoa(int(value.Get(3).Uint())) host := strings.Join([]string{a, b, c, d}, ".") port := strconv.Itoa(int(p)) return net.JoinHostPort(host, port) }
func (block *Block) RlpValueDecode(decoder *ethutil.Value) { header := decoder.Get(0) block.PrevHash = header.Get(0).Bytes() block.UncleSha = header.Get(1).Bytes() block.Coinbase = header.Get(2).Bytes() block.state = ethstate.New(ethtrie.New(ethutil.Config.Db, header.Get(3).Val)) block.TxSha = header.Get(4).Bytes() block.Difficulty = header.Get(5).BigInt() block.Number = header.Get(6).BigInt() //fmt.Printf("#%v : %x\n", block.Number, block.Coinbase) block.MinGasPrice = header.Get(7).BigInt() block.GasLimit = header.Get(8).BigInt() block.GasUsed = header.Get(9).BigInt() block.Time = int64(header.Get(10).BigInt().Uint64()) block.Extra = header.Get(11).Str() block.Nonce = header.Get(12).Bytes() // Tx list might be empty if this is an uncle. Uncles only have their // header set. if decoder.Get(1).IsNil() == false { // Yes explicitness receipts := decoder.Get(1) block.transactions = make([]*Transaction, receipts.Len()) block.receipts = make([]*Receipt, receipts.Len()) for i := 0; i < receipts.Len(); i++ { receipt := NewRecieptFromValue(receipts.Get(i)) block.transactions[i] = receipt.Tx block.receipts[i] = receipt } } if decoder.Get(2).IsNil() == false { // Yes explicitness uncles := decoder.Get(2) block.Uncles = make([]*Block, uncles.Len()) for i := 0; i < uncles.Len(); i++ { block.Uncles[i] = NewUncleBlockFromValue(uncles.Get(i)) } } }
func (block *Block) RlpValueDecode(decoder *ethutil.Value) { header := decoder.Get(0) block.PrevHash = header.Get(0).Bytes() block.UncleSha = header.Get(1).Bytes() block.Coinbase = header.Get(2).Bytes() block.state = NewState(ethutil.NewTrie(ethutil.Config.Db, header.Get(3).Val)) block.TxSha = header.Get(4).Bytes() block.Difficulty = header.Get(5).BigInt() block.Time = int64(header.Get(6).BigInt().Uint64()) block.Extra = header.Get(7).Str() block.Nonce = header.Get(8).Bytes() block.contractStates = make(map[string]*ethutil.Trie) // Tx list might be empty if this is an uncle. Uncles only have their // header set. if decoder.Get(1).IsNil() == false { // Yes explicitness txes := decoder.Get(1) block.transactions = make([]*Transaction, txes.Len()) for i := 0; i < txes.Len(); i++ { tx := NewTransactionFromValue(txes.Get(i)) block.transactions[i] = tx } } if decoder.Get(2).IsNil() == false { // Yes explicitness uncles := decoder.Get(2) block.Uncles = make([]*Block, uncles.Len()) for i := 0; i < uncles.Len(); i++ { block.Uncles[i] = NewUncleBlockFromValue(uncles.Get(i)) } } }
func (tx *Transaction) RlpValueDecode(decoder *ethutil.Value) { tx.Nonce = decoder.Get(0).Uint() tx.Recipient = decoder.Get(1).Bytes() tx.Value = decoder.Get(2).BigInt() d := decoder.Get(3) tx.Data = make([]string, d.Len()) for i := 0; i < d.Len(); i++ { tx.Data[i] = d.Get(i).Str() } // TODO something going wrong here tx.v = byte(decoder.Get(4).Uint()) tx.r = decoder.Get(5).Bytes() tx.s = decoder.Get(6).Bytes() }
func NewUncleBlockFromValue(header *ethutil.Value) *Block { block := &Block{} block.PrevHash = header.Get(0).Bytes() block.UncleSha = header.Get(1).Bytes() block.Coinbase = header.Get(2).Bytes() block.state = NewState(ethutil.NewTrie(ethutil.Config.Db, header.Get(3).Val)) block.TxSha = header.Get(4).Bytes() block.Difficulty = header.Get(5).BigInt() block.Time = int64(header.Get(6).BigInt().Uint64()) block.Extra = header.Get(7).Str() block.Nonce = header.Get(8).Bytes() return block }
func NewUncleBlockFromValue(header *ethutil.Value) *Block { block := &Block{} block.PrevHash = header.Get(0).Bytes() block.UncleSha = header.Get(1).Bytes() block.Coinbase = header.Get(2).Bytes() block.state = ethstate.New(ethtrie.New(ethutil.Config.Db, header.Get(3).Val)) block.TxSha = header.Get(4).Bytes() block.Difficulty = header.Get(5).BigInt() block.Number = header.Get(6).BigInt() block.MinGasPrice = header.Get(7).BigInt() block.GasLimit = header.Get(8).BigInt() block.GasUsed = header.Get(9).BigInt() block.Time = int64(header.Get(10).BigInt().Uint64()) block.Extra = header.Get(11).Str() block.Nonce = header.Get(12).Bytes() return block }
func (self *Receipt) RlpValueDecode(decoder *ethutil.Value) { self.Tx = NewTransactionFromValue(decoder.Get(0)) self.PostState = decoder.Get(1).Bytes() self.CumulativeGasUsed = decoder.Get(2).BigInt() }
func (tx *Transaction) RlpValueDecode(decoder *ethutil.Value) { tx.Nonce = decoder.Get(0).Uint() tx.GasPrice = decoder.Get(1).BigInt() tx.Gas = decoder.Get(2).BigInt() tx.Recipient = decoder.Get(3).Bytes() tx.Value = decoder.Get(4).BigInt() tx.Data = decoder.Get(5).Bytes() tx.v = byte(decoder.Get(6).Uint()) tx.r = decoder.Get(7).Bytes() tx.s = decoder.Get(8).Bytes() if IsContractAddr(tx.Recipient) { tx.contractCreation = true } }
func (it *TrieIterator) iterateNode(key []int, currentNode *ethutil.Value, cb EachCallback) { if currentNode.Len() == 2 { k := CompactDecode(currentNode.Get(0).Str()) pk := append(key, k...) if currentNode.Get(1).Len() != 0 && currentNode.Get(1).Str() == "" { it.iterateNode(pk, currentNode.Get(1), cb) } else { if k[len(k)-1] == 16 { cb(DecodeCompact(pk), currentNode.Get(1)) } else { it.fetchNode(pk, currentNode.Get(1).Bytes(), cb) } } } else { for i := 0; i < currentNode.Len(); i++ { pk := append(key, i) if i == 16 && currentNode.Get(i).Len() != 0 { cb(DecodeCompact(pk), currentNode.Get(i)) } else { if currentNode.Get(i).Len() != 0 && currentNode.Get(i).Str() == "" { it.iterateNode(pk, currentNode.Get(i), cb) } else { val := currentNode.Get(i).Str() if val != "" { it.fetchNode(pk, []byte(val), cb) } } } } } }
// Some time in the near future this will need refactoring :-) // XXX Note to self, IsSlice == inline node. Str == sha3 to node func (it *TrieIterator) workNode(currentNode *ethutil.Value) { if currentNode.Len() == 2 { k := CompactDecode(currentNode.Get(0).Str()) if currentNode.Get(1).Str() == "" { it.workNode(currentNode.Get(1)) } else { if k[len(k)-1] == 16 { it.values = append(it.values, currentNode.Get(1).Str()) } else { it.shas = append(it.shas, currentNode.Get(1).Bytes()) it.getNode(currentNode.Get(1).Bytes()) } } } else { for i := 0; i < currentNode.Len(); i++ { if i == 16 && currentNode.Get(i).Len() != 0 { it.values = append(it.values, currentNode.Get(i).Str()) } else { if currentNode.Get(i).Str() == "" { it.workNode(currentNode.Get(i)) } else { val := currentNode.Get(i).Str() if val != "" { it.shas = append(it.shas, currentNode.Get(1).Bytes()) it.getNode([]byte(val)) } } } } } }
func NewKeyPairFromValue(val *ethutil.Value) *KeyPair { keyPair := &KeyPair{PrivateKey: val.Get(0).Bytes(), PublicKey: val.Get(1).Bytes()} return keyPair }