use of co.rsk.core.RskAddress in project rskj by rsksmart.
the class GenesisLoader method loadGenesis.
public static Genesis loadGenesis(RskSystemProperties config, BigInteger initialNonce, InputStream genesisJsonIS, boolean isRsk) {
try {
String json = new String(ByteStreams.toByteArray(genesisJsonIS));
ObjectMapper mapper = new ObjectMapper();
JavaType type = mapper.getTypeFactory().constructType(GenesisJson.class);
GenesisJson genesisJson = new ObjectMapper().readValue(json, type);
Genesis genesis = new GenesisMapper().mapFromJson(genesisJson, isRsk);
Map<RskAddress, InitialAddressState> premine = generatePreMine(config, initialNonce, genesisJson.getAlloc());
genesis.setPremine(premine);
byte[] rootHash = generateRootHash(premine);
genesis.setStateRoot(rootHash);
genesis.flushRLP();
return genesis;
} catch (Exception e) {
System.err.println("Genesis block configuration is corrupted or not found ./resources/genesis/...");
logger.error("Genesis block configuration is corrupted or not found ./resources/genesis/...", e);
System.exit(-1);
return null;
}
}
use of co.rsk.core.RskAddress in project rskj by rsksmart.
the class BlockGenerator method generatePreMine.
private Map<RskAddress, InitialAddressState> generatePreMine(Map<byte[], BigInteger> alloc) {
Map<RskAddress, InitialAddressState> premine = new HashMap<>();
for (byte[] key : alloc.keySet()) {
AccountState acctState = new AccountState(BigInteger.valueOf(0), new Coin(alloc.get(key)));
premine.put(new RskAddress(key), new InitialAddressState(acctState, null));
}
return premine;
}
use of co.rsk.core.RskAddress in project rskj by rsksmart.
the class Web3Impl method eth_getBalance.
@Override
public String eth_getBalance(String address, String block) throws Exception {
/* HEX String - an integer block number
* String "earliest" for the earliest/genesis block
* String "latest" - for the latest mined block
* String "pending" - for the pending state/transactions
*/
Repository repository = getRepoByJsonBlockId(block);
if (repository == null) {
throw new NullPointerException();
}
RskAddress addr = new RskAddress(address);
BigInteger balance = repository.getBalance(addr).asBigInteger();
return toJsonHex(balance);
}
use of co.rsk.core.RskAddress in project rskj by rsksmart.
the class VM method computeCallGas.
private long computeCallGas(DataWord codeAddress, DataWord value, DataWord inDataOffs, DataWord inDataSize, DataWord outDataOffs, DataWord outDataSize) {
long callGas = GasCost.CALL;
// check to see if account does not exist and is not a precompiled contract
if (op == OpCode.CALL && !program.getStorage().isExist(new RskAddress(codeAddress))) {
callGas += GasCost.NEW_ACCT_CALL;
}
if (op != OpCode.DELEGATECALL && !value.isZero()) {
callGas += GasCost.VT_CALL;
}
long inSizeLong = Program.limitToMaxLong(inDataSize);
long outSizeLong = Program.limitToMaxLong(outDataSize);
// in offset+size
long in = memNeeded(inDataOffs, inSizeLong);
// out offset+size
long out = memNeeded(outDataOffs, outSizeLong);
long newMemSize = Long.max(in, out);
callGas += calcMemGas(oldMemSize, newMemSize, 0);
return callGas;
}
use of co.rsk.core.RskAddress in project rskj by rsksmart.
the class VM method dumpLine.
/*
* Dumping the VM state at the current operation in various styles
* - standard Not Yet Implemented
* - standard+ (owner address, program counter, operation, gas left)
* - pretty (stack, memory, storage, level, contract,
* vmCounter, internalSteps, operation
gasBefore, gasCost, memWords)
*/
private void dumpLine(OpCode op, long gasBefore, long gasCost, long memWords, Program program) {
if ("standard+".equals(vmConfig.dumpStyle())) {
switch(op) {
case STOP:
case RETURN:
case SUICIDE:
ContractDetails details = program.getStorage().getContractDetails(new RskAddress(program.getOwnerAddress()));
List<DataWord> storageKeys = new ArrayList<>(details.getStorage().keySet());
Collections.sort(storageKeys);
storageKeys.forEach(key -> dumpLogger.trace("{} {}", Hex.toHexString(key.getNoLeadZeroesData()), Hex.toHexString(details.getStorage().get(key).getNoLeadZeroesData())));
break;
default:
break;
}
String addressString = Hex.toHexString(program.getOwnerAddress().getLast20Bytes());
String pcString = Hex.toHexString(new DataWord(program.getPC()).getNoLeadZeroesData());
String opString = Hex.toHexString(new byte[] { op.val() });
String gasString = Long.toHexString(program.getRemainingGas());
dumpLogger.trace("{} {} {} {}", addressString, pcString, opString, gasString);
} else if ("pretty".equals(vmConfig.dumpStyle())) {
dumpLogger.trace("-------------------------------------------------------------------------");
dumpLogger.trace(" STACK");
program.getStack().forEach(item -> dumpLogger.trace("{}", item));
dumpLogger.trace(" MEMORY");
String memoryString = program.memoryToString();
if (!"".equals(memoryString)) {
dumpLogger.trace("{}", memoryString);
}
dumpLogger.trace(" STORAGE");
ContractDetails details = program.getStorage().getContractDetails(new RskAddress(program.getOwnerAddress()));
List<DataWord> storageKeys = new ArrayList<>(details.getStorage().keySet());
Collections.sort(storageKeys);
storageKeys.forEach(key -> dumpLogger.trace("{}: {}", key.shortHex(), details.getStorage().get(key).shortHex()));
int level = program.getCallDeep();
String contract = Hex.toHexString(program.getOwnerAddress().getLast20Bytes());
String internalSteps = String.format("%4s", Integer.toHexString(program.getPC())).replace(' ', '0').toUpperCase();
dumpLogger.trace("{} | {} | #{} | {} : {} | {} | -{} | {}x32", level, contract, vmCounter, internalSteps, op, gasBefore, gasCost, memWords);
}
}
Aggregations