Search in sources :

Example 1 with AccountInformationProvider

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());
}
Also used : Coin(co.rsk.core.Coin) RskAddress(co.rsk.core.RskAddress) AccountInformationProvider(co.rsk.core.bc.AccountInformationProvider)

Example 2 with AccountInformationProvider

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);
        }
    }
}
Also used : RskAddress(co.rsk.core.RskAddress) BigInteger(java.math.BigInteger) AccountInformationProvider(co.rsk.core.bc.AccountInformationProvider)

Example 3 with AccountInformationProvider

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);
}
Also used : RepositorySnapshot(co.rsk.db.RepositorySnapshot) AccountInformationProvider(co.rsk.core.bc.AccountInformationProvider) Test(org.junit.Test)

Example 4 with AccountInformationProvider

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);
}
Also used : RepositorySnapshot(co.rsk.db.RepositorySnapshot) AccountInformationProvider(co.rsk.core.bc.AccountInformationProvider) Test(org.junit.Test)

Example 5 with AccountInformationProvider

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);
        }
    }
}
Also used : RskAddress(co.rsk.core.RskAddress) AccountInformationProvider(co.rsk.core.bc.AccountInformationProvider)

Aggregations

AccountInformationProvider (co.rsk.core.bc.AccountInformationProvider)11 RskAddress (co.rsk.core.RskAddress)7 Test (org.junit.Test)7 RepositorySnapshot (co.rsk.db.RepositorySnapshot)3 DataWord (org.ethereum.vm.DataWord)3 Coin (co.rsk.core.Coin)2 PendingState (co.rsk.core.bc.PendingState)1 BigInteger (java.math.BigInteger)1