diff --git a/ethereumj-core/src/main/java/org/ethereum/vm/Program.java b/ethereumj-core/src/main/java/org/ethereum/vm/Program.java index 28d15a18..1efcd2da 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/Program.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/Program.java @@ -214,13 +214,14 @@ public class Program { public void suicide(DataWord obtainer) { + DataWord balance = getBalance(this.getOwnerAddress()); // 1) pass full endowment to the obtainer if (logger.isInfoEnabled()) logger.info("Transfer to: [ {} ] heritage: [ {} ]", Hex.toHexString(obtainer.getNoLeadZeroesData()) - , getBalance().longValue()); + , balance.longValue()); this.result.getRepository().addBalance(obtainer.getNoLeadZeroesData(), - getBalance().value()); + balance.value()); // 2) mark the account as for delete result.addDeleteAccount(getOwnerAddress()); @@ -460,9 +461,13 @@ public class Program { return invokeData.getOwnerAddress(); } - public DataWord getBalance() { + public DataWord getBalance(DataWord address) { if (invokeData == null) return new DataWord( new byte[0]); - return invokeData.getBalance(); + + BigInteger balance = result.getRepository().getBalance(address.getNoLeadZeroesData()); + DataWord balanceData = new DataWord(balance.toByteArray()); + + return balanceData; } public DataWord getOriginAddress() { diff --git a/ethereumj-core/src/main/java/org/ethereum/vm/VM.java b/ethereumj-core/src/main/java/org/ethereum/vm/VM.java index d841ba01..0fff615c 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/VM.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/VM.java @@ -297,7 +297,8 @@ public class VM { program.step(); } break; case BALANCE:{ - DataWord balance = program.getBalance(); + DataWord address = program.stackPop(); + DataWord balance = program.getBalance(address); program.stackPush(balance); program.step(); } break; @@ -504,6 +505,8 @@ public class VM { program.stackPush(data); } break; case CREATE:{ + + //todo: value param for gas param, the gas is all gas DataWord gas = program.stackPop(); DataWord inOffset = program.stackPop(); DataWord inSize = program.stackPop(); diff --git a/ethereumj-core/src/test/java/org/ethereum/vm/VMTest.java b/ethereumj-core/src/test/java/org/ethereum/vm/VMTest.java index 2c18ee08..c737d80e 100644 --- a/ethereumj-core/src/test/java/org/ethereum/vm/VMTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/vm/VMTest.java @@ -6,6 +6,8 @@ import org.junit.Test; import org.junit.runners.MethodSorters; import org.spongycastle.util.encoders.Hex; +import java.math.BigInteger; + import static org.junit.Assert.*; /** @@ -2681,10 +2683,11 @@ public class VMTest { VM vm = new VM(); Program program = - new Program(Hex.decode("31"), + new Program(Hex.decode("3031"), createProgramInvoke_1()); - String s_expected_1 = "0000000000000000000000000000000000000000000000000DE0B6B3A7640000"; + String s_expected_1 = "00000000000000000000000000000000000000000000000000000000000003E8"; + vm.step(program); vm.step(program); DataWord item1 = program.stack.pop(); @@ -3070,6 +3073,7 @@ public class VMTest { pi.setOwnerAddress(ownerAddress); pi.getRepository().createAccount(address); + pi.getRepository().addBalance(address, BigInteger.valueOf(1000L)); return pi; }