aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-03-30 18:58:37 +0800
committerobscuren <geffobscura@gmail.com>2014-03-30 18:58:37 +0800
commit6625b6ffbdb93a47de2187198d6e826fb32c1ba6 (patch)
treef61c2d9e13b8e208bd7c9032db6ccbaa90fde08e
parentb888652201277ab86e9e8c280e75e23ced5e3d38 (diff)
downloadgo-tangerine-6625b6ffbdb93a47de2187198d6e826fb32c1ba6.tar
go-tangerine-6625b6ffbdb93a47de2187198d6e826fb32c1ba6.tar.gz
go-tangerine-6625b6ffbdb93a47de2187198d6e826fb32c1ba6.tar.bz2
go-tangerine-6625b6ffbdb93a47de2187198d6e826fb32c1ba6.tar.lz
go-tangerine-6625b6ffbdb93a47de2187198d6e826fb32c1ba6.tar.xz
go-tangerine-6625b6ffbdb93a47de2187198d6e826fb32c1ba6.tar.zst
go-tangerine-6625b6ffbdb93a47de2187198d6e826fb32c1ba6.zip
Changed to new mutan API
-rw-r--r--ethchain/state_manager.go26
-rw-r--r--ethchain/vm_test.go27
2 files changed, 28 insertions, 25 deletions
diff --git a/ethchain/state_manager.go b/ethchain/state_manager.go
index 3b5507740..5c693442b 100644
--- a/ethchain/state_manager.go
+++ b/ethchain/state_manager.go
@@ -100,16 +100,21 @@ func (sm *StateManager) MakeContract(tx *Transaction) {
}
}
+// Apply transactions uses the transaction passed to it and applies them onto
+// the current processing state.
func (sm *StateManager) ApplyTransactions(block *Block, txs []*Transaction) {
// Process each transaction/contract
for _, tx := range txs {
// If there's no recipient, it's a contract
+ // Check if this is a contract creation traction and if so
+ // create a contract of this tx.
if tx.IsContract() {
sm.MakeContract(tx)
- //XXX block.MakeContract(tx)
} else {
+ // Figure out if the address this transaction was sent to is a
+ // contract or an actual account. In case of a contract, we process that
+ // contract instead of moving funds between accounts.
if contract := sm.procState.GetContract(tx.Recipient); contract != nil {
- //XXX if contract := block.state.GetContract(tx.Recipient); contract != nil {
sm.ProcessContract(contract, tx, block)
} else {
err := sm.Ethereum.TxPool().ProcessTransaction(tx, block)
@@ -172,14 +177,12 @@ func (sm *StateManager) ProcessBlock(block *Block) error {
// if !sm.compState.Cmp(sm.procState)
if !sm.compState.Cmp(sm.procState) {
- //XXX return fmt.Errorf("Invalid merkle root. Expected %x, got %x", block.State().trie.Root, sm.bc.CurrentBlock.State().trie.Root)
return fmt.Errorf("Invalid merkle root. Expected %x, got %x", sm.compState.trie.Root, sm.procState.trie.Root)
}
// Calculate the new total difficulty and sync back to the db
if sm.CalculateTD(block) {
// Sync the current block's state to the database and cancelling out the deferred Undo
- //XXX sm.bc.CurrentBlock.Sync()
sm.procState.Sync()
// Broadcast the valid block back to the wire
@@ -273,12 +276,10 @@ func CalculateUncleReward(block *Block) *big.Int {
func (sm *StateManager) AccumelateRewards(block *Block) error {
// Get the coinbase rlp data
- //XXX addr := processor.state.GetAccount(block.Coinbase)
addr := sm.procState.GetAccount(block.Coinbase)
// Reward amount of ether to the coinbase address
addr.AddFee(CalculateBlockReward(block, len(block.Uncles)))
- //XXX processor.state.UpdateAccount(block.Coinbase, addr)
sm.procState.UpdateAccount(block.Coinbase, addr)
for _, uncle := range block.Uncles {
@@ -298,13 +299,12 @@ func (sm *StateManager) Stop() {
func (sm *StateManager) ProcessContract(contract *Contract, tx *Transaction, block *Block) {
// Recovering function in case the VM had any errors
- /*
- defer func() {
- if r := recover(); r != nil {
- fmt.Println("Recovered from VM execution with err =", r)
- }
- }()
- */
+ defer func() {
+ if r := recover(); r != nil {
+ fmt.Println("Recovered from VM execution with err =", r)
+ }
+ }()
+
caller := sm.procState.GetAccount(tx.Sender())
closure := NewClosure(caller, contract, sm.procState, tx.Gas, tx.Value)
vm := NewVm(sm.procState, RuntimeVars{
diff --git a/ethchain/vm_test.go b/ethchain/vm_test.go
index c802420cb..589f0bf4a 100644
--- a/ethchain/vm_test.go
+++ b/ethchain/vm_test.go
@@ -81,18 +81,21 @@ func TestRun4(t *testing.T) {
db, _ := ethdb.NewMemDatabase()
state := NewState(ethutil.NewTrie(db, ""))
- mutan.NewCompiler().Compile(strings.NewReader(`
-a = 1337
-c = 1
-store[0] = 50
-d = store[0]
-`))
-
- asm, _ := mutan.NewCompiler().Compile(strings.NewReader(`
- a = 3 + 3
- store[1000] = a
- store[1000]
-`))
+ mutan.Compile(strings.NewReader(`
+ a = 1337
+ c = 1
+ store[0] = 50
+ d = store[0]
+ `), false)
+
+ asm, err := mutan.Compile(strings.NewReader(`
+ a = 3 + 3
+ store[1000] = a
+ store[1000]
+ `), false)
+ if err != nil {
+ fmt.Println(err)
+ }
asm = append(asm, "LOG")
fmt.Println(asm)