use of co.rsk.core.bc.AccountInformationProvider in project rskj by rsksmart.
the class Web3Impl method eth_getBalance.
@Override
public String eth_getBalance(String address, String block) {
/* 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
*/
AccountInformationProvider accountInformationProvider = web3InformationRetriever.getInformationProvider(block);
RskAddress addr = new RskAddress(address);
Coin balance = accountInformationProvider.getBalance(addr);
return toQuantityJsonHex(balance.asBigInteger());
}
use of co.rsk.core.bc.AccountInformationProvider in project rskj by rsksmart.
the class Web3Impl method eth_getTransactionCount.
@Override
public String eth_getTransactionCount(String address, String blockId) {
String s = null;
try {
RskAddress addr = new RskAddress(address);
AccountInformationProvider accountInformationProvider = web3InformationRetriever.getInformationProvider(blockId);
BigInteger nonce = accountInformationProvider.getNonce(addr);
s = toQuantityJsonHex(nonce);
return s;
} finally {
if (logger.isDebugEnabled()) {
logger.debug("eth_getTransactionCount({}, {}): {}", address, blockId, s);
}
}
}
use of co.rsk.core.bc.AccountInformationProvider in project rskj by rsksmart.
the class Web3InformationRetrieverTest method getState_earliest.
@Test
public void getState_earliest() {
Block block = mock(Block.class);
BlockHeader header = mock(BlockHeader.class);
when(block.getHeader()).thenReturn(header);
when(blockchain.getBlockByNumber(0)).thenReturn(block);
RepositorySnapshot snapshot = mock(RepositorySnapshot.class);
when(locator.findSnapshotAt(eq(header))).thenReturn(Optional.of(snapshot));
AccountInformationProvider result = target.getInformationProvider("earliest");
assertEquals(snapshot, result);
}
use of co.rsk.core.bc.AccountInformationProvider in project rskj by rsksmart.
the class Web3InformationRetrieverTest method getState_number.
@Test
public void getState_number() {
Block block = mock(Block.class);
BlockHeader header = mock(BlockHeader.class);
when(block.getHeader()).thenReturn(header);
when(blockchain.getBlockByNumber(4)).thenReturn(block);
RepositorySnapshot snapshot = mock(RepositorySnapshot.class);
when(locator.findSnapshotAt(eq(header))).thenReturn(Optional.of(snapshot));
AccountInformationProvider result = target.getInformationProvider("0x4");
assertEquals(snapshot, result);
}
use of co.rsk.core.bc.AccountInformationProvider in project rskj by rsksmart.
the class EthModule method getCode.
public String getCode(String address, String blockId) {
if (blockId == null) {
throw new NullPointerException();
}
String s = null;
try {
RskAddress addr = new RskAddress(address);
AccountInformationProvider accountInformationProvider = getAccountInformationProvider(blockId);
if (accountInformationProvider != null) {
byte[] code = accountInformationProvider.getCode(addr);
// Code can be null, if there is no account.
if (code == null) {
code = new byte[0];
}
s = toUnformattedJsonHex(code);
}
return s;
} finally {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("eth_getCode({}, {}): {}", address, blockId, s);
}
}
}
Aggregations