Exemple #1
0
func CreateBlock(root interface{},
	prevHash []byte,
	base []byte,
	Difficulty *big.Int,
	Nonce []byte,
	extra string) *Block {

	block := &Block{
		PrevHash:    prevHash,
		Coinbase:    base,
		Difficulty:  Difficulty,
		Nonce:       Nonce,
		Time:        time.Now().Unix(),
		Extra:       extra,
		UncleSha:    EmptyShaList,
		GasUsed:     new(big.Int),
		MinGasPrice: new(big.Int),
		GasLimit:    new(big.Int),
	}
	block.SetUncles([]*Block{})

	block.state = ethstate.New(ethtrie.New(ethutil.Config.Db, root))

	return block
}
Exemple #2
0
// Converts an transaction in to a state object
func MakeContract(tx *Transaction, state *ethstate.State) *ethstate.StateObject {
	// Create contract if there's no recipient
	if tx.IsContract() {
		addr := tx.CreationAddress()

		contract := state.NewStateObject(addr)
		contract.InitCode = tx.Data
		contract.State = ethstate.New(ethtrie.New(ethutil.Config.Db, ""))

		return contract
	}

	return nil
}
Exemple #3
0
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
}
Exemple #4
0
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))
		}
	}

}