mirror of
https://github.com/status-im/ethereumj-personal.git
synced 2025-02-17 06:06:23 +00:00
Fixed BALANCE usage
+ spec changed to retrieve BALANCE by the specified address
This commit is contained in:
parent
e6836a0b63
commit
db450e2233
@ -214,13 +214,14 @@ public class Program {
|
|||||||
|
|
||||||
public void suicide(DataWord obtainer) {
|
public void suicide(DataWord obtainer) {
|
||||||
|
|
||||||
|
DataWord balance = getBalance(this.getOwnerAddress());
|
||||||
// 1) pass full endowment to the obtainer
|
// 1) pass full endowment to the obtainer
|
||||||
if (logger.isInfoEnabled())
|
if (logger.isInfoEnabled())
|
||||||
logger.info("Transfer to: [ {} ] heritage: [ {} ]", Hex.toHexString(obtainer.getNoLeadZeroesData())
|
logger.info("Transfer to: [ {} ] heritage: [ {} ]", Hex.toHexString(obtainer.getNoLeadZeroesData())
|
||||||
, getBalance().longValue());
|
, balance.longValue());
|
||||||
|
|
||||||
this.result.getRepository().addBalance(obtainer.getNoLeadZeroesData(),
|
this.result.getRepository().addBalance(obtainer.getNoLeadZeroesData(),
|
||||||
getBalance().value());
|
balance.value());
|
||||||
|
|
||||||
// 2) mark the account as for delete
|
// 2) mark the account as for delete
|
||||||
result.addDeleteAccount(getOwnerAddress());
|
result.addDeleteAccount(getOwnerAddress());
|
||||||
@ -460,9 +461,13 @@ public class Program {
|
|||||||
return invokeData.getOwnerAddress();
|
return invokeData.getOwnerAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataWord getBalance() {
|
public DataWord getBalance(DataWord address) {
|
||||||
if (invokeData == null) return new DataWord( new byte[0]);
|
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() {
|
public DataWord getOriginAddress() {
|
||||||
|
@ -297,7 +297,8 @@ public class VM {
|
|||||||
program.step();
|
program.step();
|
||||||
} break;
|
} break;
|
||||||
case BALANCE:{
|
case BALANCE:{
|
||||||
DataWord balance = program.getBalance();
|
DataWord address = program.stackPop();
|
||||||
|
DataWord balance = program.getBalance(address);
|
||||||
program.stackPush(balance);
|
program.stackPush(balance);
|
||||||
program.step();
|
program.step();
|
||||||
} break;
|
} break;
|
||||||
@ -504,6 +505,8 @@ public class VM {
|
|||||||
program.stackPush(data);
|
program.stackPush(data);
|
||||||
} break;
|
} break;
|
||||||
case CREATE:{
|
case CREATE:{
|
||||||
|
|
||||||
|
//todo: value param for gas param, the gas is all gas
|
||||||
DataWord gas = program.stackPop();
|
DataWord gas = program.stackPop();
|
||||||
DataWord inOffset = program.stackPop();
|
DataWord inOffset = program.stackPop();
|
||||||
DataWord inSize = program.stackPop();
|
DataWord inSize = program.stackPop();
|
||||||
|
@ -6,6 +6,8 @@ import org.junit.Test;
|
|||||||
import org.junit.runners.MethodSorters;
|
import org.junit.runners.MethodSorters;
|
||||||
import org.spongycastle.util.encoders.Hex;
|
import org.spongycastle.util.encoders.Hex;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2681,10 +2683,11 @@ public class VMTest {
|
|||||||
|
|
||||||
VM vm = new VM();
|
VM vm = new VM();
|
||||||
Program program =
|
Program program =
|
||||||
new Program(Hex.decode("31"),
|
new Program(Hex.decode("3031"),
|
||||||
createProgramInvoke_1());
|
createProgramInvoke_1());
|
||||||
String s_expected_1 = "0000000000000000000000000000000000000000000000000DE0B6B3A7640000";
|
String s_expected_1 = "00000000000000000000000000000000000000000000000000000000000003E8";
|
||||||
|
|
||||||
|
vm.step(program);
|
||||||
vm.step(program);
|
vm.step(program);
|
||||||
|
|
||||||
DataWord item1 = program.stack.pop();
|
DataWord item1 = program.stack.pop();
|
||||||
@ -3070,6 +3073,7 @@ public class VMTest {
|
|||||||
pi.setOwnerAddress(ownerAddress);
|
pi.setOwnerAddress(ownerAddress);
|
||||||
|
|
||||||
pi.getRepository().createAccount(address);
|
pi.getRepository().createAccount(address);
|
||||||
|
pi.getRepository().addBalance(address, BigInteger.valueOf(1000L));
|
||||||
|
|
||||||
return pi;
|
return pi;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user