Search in sources :

Example 6 with Wei

use of org.hyperledger.besu.datatypes.Wei in project besu by hyperledger.

the class GraphQLHttpServiceTest method query_untypedPost.

@Test
public void query_untypedPost() throws Exception {
    final RequestBody body = RequestBody.create("{gasPrice}", null);
    final Wei price = Wei.of(16);
    Mockito.when(miningCoordinatorMock.getMinTransactionGasPrice()).thenReturn(price);
    try (final Response resp = client.newCall(buildPostRequest(body)).execute()) {
        // Check general format of result
        Assertions.assertThat(resp.code()).isEqualTo(200);
        final JsonObject json = new JsonObject(resp.body().string());
        testHelper.assertValidGraphQLResult(json);
        final String result = json.getJsonObject("data").getString("gasPrice");
        Assertions.assertThat(result).isEqualTo("0x10");
    }
}
Also used : Response(okhttp3.Response) JsonObject(io.vertx.core.json.JsonObject) Wei(org.hyperledger.besu.datatypes.Wei) RequestBody(okhttp3.RequestBody) Test(org.junit.Test)

Example 7 with Wei

use of org.hyperledger.besu.datatypes.Wei in project besu by hyperledger.

the class FixedKeySigningPrivateMarkerTransactionFactoryTest method createsFullyPopulatedPrivateMarkerTransactionUsingProvidedNonce.

@Test
public void createsFullyPopulatedPrivateMarkerTransactionUsingProvidedNonce() {
    final PrivateTransaction privTransaction = mock(PrivateTransaction.class);
    final Wei gasPrice = Wei.of(100);
    final long gasLimit = 500;
    final long providedNonce = 100;
    final String enclaveKey = "pmtLookupKey";
    final KeyPair signingKeys = SignatureAlgorithmFactory.getInstance().generateKeyPair();
    final Address precompiledAddress = Address.fromHexString("1");
    final FixedKeySigningPrivateMarkerTransactionFactory factory = new FixedKeySigningPrivateMarkerTransactionFactory(signingKeys);
    final Transaction unsignedPrivateMarkerTransaction = new Transaction.Builder().type(TransactionType.FRONTIER).nonce(providedNonce).gasPrice(gasPrice).gasLimit(gasLimit).to(precompiledAddress).value(Wei.ZERO).payload(Bytes.fromBase64String(enclaveKey)).build();
    final Transaction transaction = Transaction.readFrom(factory.create(unsignedPrivateMarkerTransaction, privTransaction, ""));
    assertThat(transaction.getNonce()).isEqualTo(providedNonce);
    assertThat(transaction.getGasLimit()).isEqualTo(gasLimit);
    assertThat(transaction.getGasPrice().get()).isEqualTo(gasPrice);
    assertThat(transaction.getValue()).isEqualTo(Wei.ZERO);
    assertThat(transaction.getSender()).isEqualTo(Util.publicKeyToAddress(signingKeys.getPublicKey()));
    assertThat(transaction.getTo()).isEqualTo(Optional.of(precompiledAddress));
    assertThat(transaction.getPayload()).isEqualTo(Bytes.fromBase64String(enclaveKey));
    final Transaction nextTransaction = Transaction.readFrom(factory.create(unsignedPrivateMarkerTransaction, privTransaction, ""));
    assertThat(nextTransaction.getSender()).isEqualTo(transaction.getSender());
}
Also used : PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) KeyPair(org.hyperledger.besu.crypto.KeyPair) Address(org.hyperledger.besu.datatypes.Address) PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) Transaction(org.hyperledger.besu.ethereum.core.Transaction) Wei(org.hyperledger.besu.datatypes.Wei) Test(org.junit.Test)

Example 8 with Wei

use of org.hyperledger.besu.datatypes.Wei in project besu by hyperledger.

the class RandomSigningPrivateMarkerTransactionFactoryTest method producedTransactionHasZeroNonceAndDifferentSendThanPrior.

@Test
public void producedTransactionHasZeroNonceAndDifferentSendThanPrior() {
    final PrivateTransaction privTransaction = mock(PrivateTransaction.class);
    final Wei gasPrice = Wei.of(100);
    final long gasLimit = 500;
    final String enclaveKey = "enclaveKey";
    final long providedNonce = 0;
    final Address precompiledAddress = Address.fromHexString("1");
    final Transaction unsignedPrivateMarkerTransaction = new Transaction.Builder().type(TransactionType.FRONTIER).nonce(providedNonce).gasPrice(gasPrice).gasLimit(gasLimit).to(precompiledAddress).value(Wei.ZERO).payload(Bytes.fromBase64String(enclaveKey)).build();
    final RandomSigningPrivateMarkerTransactionFactory factory = new RandomSigningPrivateMarkerTransactionFactory();
    final Transaction transaction = Transaction.readFrom(factory.create(unsignedPrivateMarkerTransaction, privTransaction, ""));
    assertThat(transaction.getNonce()).isEqualTo(0);
    assertThat(transaction.getGasLimit()).isEqualTo(gasLimit);
    assertThat(transaction.getGasPrice().get()).isEqualTo(gasPrice);
    assertThat(transaction.getValue()).isEqualTo(Wei.ZERO);
    assertThat(transaction.getTo()).isEqualTo(Optional.of(precompiledAddress));
    assertThat(transaction.getPayload()).isEqualTo(Bytes.fromBase64String(enclaveKey));
    final Transaction nextTransaction = Transaction.readFrom(factory.create(unsignedPrivateMarkerTransaction, privTransaction, ""));
    assertThat(nextTransaction.getSender()).isNotEqualTo(transaction.getSender());
}
Also used : PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) Address(org.hyperledger.besu.datatypes.Address) PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) Transaction(org.hyperledger.besu.ethereum.core.Transaction) Wei(org.hyperledger.besu.datatypes.Wei) Test(org.junit.Test)

Example 9 with Wei

use of org.hyperledger.besu.datatypes.Wei in project besu by hyperledger.

the class StateTestVersionedTransaction method get.

public Transaction get(final GeneralStateTestCaseSpec.Indexes indexes) {
    Long gasLimit = gasLimits.get(indexes.gas);
    Wei value = values.get(indexes.value);
    Bytes data = payloads.get(indexes.data);
    if (value == null || gasLimit == null) {
        // this means one of the params is an out-of-bounds value. Don't generate the transaction.
        return null;
    }
    final Transaction.Builder transactionBuilder = Transaction.builder().nonce(nonce).gasLimit(gasLimit).to(to).value(value).payload(data);
    Optional.ofNullable(gasPrice).ifPresent(transactionBuilder::gasPrice);
    Optional.ofNullable(maxFeePerGas).ifPresent(transactionBuilder::maxFeePerGas);
    Optional.ofNullable(maxPriorityFeePerGas).ifPresent(transactionBuilder::maxPriorityFeePerGas);
    maybeAccessLists.ifPresent(accessLists -> transactionBuilder.accessList(accessLists.get(indexes.data)));
    transactionBuilder.guessType();
    if (transactionBuilder.getTransactionType().requiresChainId()) {
        transactionBuilder.chainId(BigInteger.ONE);
    }
    return transactionBuilder.signAndBuild(keys);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Transaction(org.hyperledger.besu.ethereum.core.Transaction) Wei(org.hyperledger.besu.datatypes.Wei)

Example 10 with Wei

use of org.hyperledger.besu.datatypes.Wei in project besu by hyperledger.

the class EthGetMinerDataByBlockHash method createMinerDataResult.

public static MinerDataResult createMinerDataResult(final BlockWithMetadata<TransactionWithMetadata, Hash> block, final ProtocolSchedule protocolSchedule, final BlockchainQueries blockchainQueries) {
    final BlockHeader blockHeader = block.getHeader();
    final ProtocolSpec protocolSpec = protocolSchedule.getByBlockNumber(blockHeader.getNumber());
    final Wei staticBlockReward = protocolSpec.getBlockReward();
    final Wei transactionFee = block.getTransactions().stream().map(t -> blockchainQueries.transactionReceiptByTransactionHash(t.getTransaction().getHash()).map(receipt -> receipt.getTransaction().getEffectiveGasPrice(receipt.getBaseFee()).multiply(receipt.getGasUsed())).orElse(Wei.ZERO)).reduce(Wei.ZERO, BaseUInt256Value::add);
    final Wei uncleInclusionReward = staticBlockReward.multiply(block.getOmmers().size()).divide(32);
    final Wei netBlockReward = staticBlockReward.add(transactionFee).add(uncleInclusionReward);
    final List<UncleRewardResult> uncleRewards = new ArrayList<>();
    blockchainQueries.getBlockchain().getBlockByNumber(block.getHeader().getNumber()).ifPresent(blockBody -> blockBody.getBody().getOmmers().forEach(header -> uncleRewards.add(ImmutableUncleRewardResult.builder().hash(header.getHash().toHexString()).coinbase(header.getCoinbase().toHexString()).build())));
    return ImmutableMinerDataResult.builder().netBlockReward(netBlockReward.toHexString()).staticBlockReward(staticBlockReward.toHexString()).transactionFee(transactionFee.toHexString()).uncleInclusionReward(uncleInclusionReward.toHexString()).uncleRewards(uncleRewards).coinbase(blockHeader.getCoinbase().toHexString()).extraData(blockHeader.getExtraData().toHexString()).difficulty(blockHeader.getDifficulty().toHexString()).totalDifficulty(block.getTotalDifficulty().toHexString()).build();
}
Also used : ImmutableMinerDataResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.ImmutableMinerDataResult) BaseUInt256Value(org.apache.tuweni.units.bigints.BaseUInt256Value) MinerDataResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.MinerDataResult) ImmutableUncleRewardResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.ImmutableUncleRewardResult) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) JsonRpcResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) Supplier(java.util.function.Supplier) UncleRewardResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.MinerDataResult.UncleRewardResult) ArrayList(java.util.ArrayList) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) List(java.util.List) RpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod) BlockWithMetadata(org.hyperledger.besu.ethereum.api.query.BlockWithMetadata) TransactionWithMetadata(org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata) Wei(org.hyperledger.besu.datatypes.Wei) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) Suppliers(com.google.common.base.Suppliers) ProtocolSpec(org.hyperledger.besu.ethereum.mainnet.ProtocolSpec) Hash(org.hyperledger.besu.datatypes.Hash) BaseUInt256Value(org.apache.tuweni.units.bigints.BaseUInt256Value) ImmutableUncleRewardResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.ImmutableUncleRewardResult) UncleRewardResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.MinerDataResult.UncleRewardResult) ProtocolSpec(org.hyperledger.besu.ethereum.mainnet.ProtocolSpec) ArrayList(java.util.ArrayList) Wei(org.hyperledger.besu.datatypes.Wei) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader)

Aggregations

Wei (org.hyperledger.besu.datatypes.Wei)69 Address (org.hyperledger.besu.datatypes.Address)24 Test (org.junit.Test)20 Transaction (org.hyperledger.besu.ethereum.core.Transaction)18 Bytes (org.apache.tuweni.bytes.Bytes)16 Hash (org.hyperledger.besu.datatypes.Hash)14 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)13 MutableAccount (org.hyperledger.besu.evm.account.MutableAccount)12 Account (org.hyperledger.besu.evm.account.Account)9 WorldUpdater (org.hyperledger.besu.evm.worldstate.WorldUpdater)9 Optional (java.util.Optional)8 TransactionInvalidReason (org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason)7 ArrayList (java.util.ArrayList)6 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)6 ProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule)6 JsonObject (io.vertx.core.json.JsonObject)5 Response (okhttp3.Response)5 Bytes32 (org.apache.tuweni.bytes.Bytes32)5 MessageFrame (org.hyperledger.besu.evm.frame.MessageFrame)5 List (java.util.List)4