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) {
|
||||
|
||||
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() {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue