func CreateBlock(root interface{}, prevHash []byte, base []byte, Difficulty *big.Int, Nonce []byte, extra string, txes []*Transaction) *Block { block := &Block{ // Slice of transactions to include in this block transactions: txes, PrevHash: prevHash, Coinbase: base, Difficulty: Difficulty, Nonce: Nonce, Time: time.Now().Unix(), Extra: extra, UncleSha: EmptyShaList, contractStates: make(map[string]*ethutil.Trie), } block.SetTransactions(txes) block.SetUncles([]*Block{}) block.state = NewState(ethutil.NewTrie(ethutil.Config.Db, root)) for _, tx := range txes { block.MakeContract(tx) } return block }
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, }) }
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())) }
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 (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 NewConsole(s *eth.Ethereum) *Console { db, _ := ethdb.NewMemDatabase() trie := ethutil.NewTrie(db, "") return &Console{db: db, trie: trie, ethereum: s} }
func NewContract(Amount *big.Int, root []byte) *Contract { contract := &Contract{Amount: Amount, Nonce: 0} contract.state = NewState(ethutil.NewTrie(ethutil.Config.Db, string(root))) return contract }