Skip to content

Commit

Permalink
Merge pull request #77 from jimni1222/customGasPrice
Browse files Browse the repository at this point in the history
Custom gas price
  • Loading branch information
jimni1222 committed Mar 11, 2020
2 parents 21217f5 + 6a8941a commit 065bb1e
Show file tree
Hide file tree
Showing 9 changed files with 314 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/src/main/java/com/klaytn/caver/tx/SmartContract.java
Expand Up @@ -374,6 +374,7 @@ KlayTransactionReceipt.TransactionReceipt executeTransaction(
transactionManager.getDefaultAddress(),
pebValue,
Numeric.hexStringToByteArray(data),
gasProvider.getGasPrice(funcName),
gasProvider.getGasLimit(funcName),
CodeFormat.EVM
);
Expand All @@ -383,6 +384,7 @@ KlayTransactionReceipt.TransactionReceipt executeTransaction(
contractAddress,
pebValue,
Numeric.hexStringToByteArray(data),
gasProvider.getGasPrice(funcName),
gasProvider.getGasLimit(funcName)
);
}
Expand Down
Expand Up @@ -20,6 +20,7 @@

package com.klaytn.caver.tx.gas;

import com.klaytn.caver.Caver;
import com.klaytn.caver.tx.ManagedTransaction;
import com.klaytn.caver.tx.SmartContract;
import org.web3j.tx.gas.StaticGasProvider;
Expand All @@ -33,4 +34,8 @@ public class DefaultGasProvider extends StaticGasProvider {
public DefaultGasProvider() {
super(GAS_PRICE, GAS_LIMIT);
}

public DefaultGasProvider(Caver caver) throws Exception{
super(caver.klay().getGasPrice().send().getValue(), GAS_LIMIT);
}
}
Expand Up @@ -34,10 +34,19 @@ private AccountUpdateTransaction(String from, AccountKey accountKey, BigInteger
this.accountKey = accountKey;
}

private AccountUpdateTransaction(String from, AccountKey accountKey, BigInteger gasPrice, BigInteger gasLimit) {
super(from, gasPrice, gasLimit);
this.accountKey = accountKey;
}

public static AccountUpdateTransaction create(String from, AccountKey accountKey, BigInteger gasLimit) {
return new AccountUpdateTransaction(from, accountKey, gasLimit);
}

public static AccountUpdateTransaction create(String from, AccountKey accountKey, BigInteger gasPrice, BigInteger gasLimit) {
return new AccountUpdateTransaction(from, accountKey, gasPrice, gasLimit);
}

public AccountUpdateTransaction feeRatio(BigInteger feeRatio) {
this.feeRatio = feeRatio;
return this;
Expand Down
Expand Up @@ -30,11 +30,18 @@ public class CancelTransaction extends TransactionTransformer<CancelTransaction>
private CancelTransaction(String from, BigInteger gasLimit) {
super(from, gasLimit);
}
private CancelTransaction(String from, BigInteger gasPrice, BigInteger gasLimit) {
super(from, gasPrice, gasLimit);
}

public static CancelTransaction create(String from, BigInteger gasLimit) {
return new CancelTransaction(from, gasLimit);
}

public static CancelTransaction create(String from, BigInteger gasPrice, BigInteger gasLimit) {
return new CancelTransaction(from, gasPrice, gasLimit);
}

public CancelTransaction feeRatio(BigInteger feeRatio) {
this.feeRatio = feeRatio;
return this;
Expand Down
Expand Up @@ -37,11 +37,23 @@ private SmartContractDeployTransaction(String from, BigInteger amount, byte[] pa
this.codeFormat = codeFormat;
}

private SmartContractDeployTransaction(String from, BigInteger amount, byte[] payload, BigInteger gasPrice, BigInteger gasLimit, BigInteger codeFormat) {
super(from, gasPrice, gasLimit);
this.amount = amount;
this.payload = payload;
this.codeFormat = codeFormat;
}

public static SmartContractDeployTransaction create(
String from, BigInteger amount, byte[] payload, BigInteger gasLimit, BigInteger codeFormat) {
return new SmartContractDeployTransaction(from, amount, payload, gasLimit, codeFormat);
}

public static SmartContractDeployTransaction create(
String from, BigInteger amount, byte[] payload, BigInteger gasPrice, BigInteger gasLimit, BigInteger codeFormat) {
return new SmartContractDeployTransaction(from, amount, payload, gasPrice, gasLimit, codeFormat);
}

public SmartContractDeployTransaction feeRatio(BigInteger feeRatio) {
this.feeRatio = feeRatio;
return this;
Expand Down
Expand Up @@ -38,11 +38,24 @@ private SmartContractExecutionTransaction(String from, String recipient, BigInte
this.payload = payload;
}

private SmartContractExecutionTransaction(String from, String recipient, BigInteger amount,
byte[] payload, BigInteger gasPrice, BigInteger gasLimit) {
super(from, gasPrice, gasLimit);
this.recipient = recipient;
this.amount = amount;
this.payload = payload;
}

public static SmartContractExecutionTransaction create(String from, String recipient, BigInteger amount,
byte[] payload, BigInteger gasLimit) {
return new SmartContractExecutionTransaction(from, recipient, amount, payload, gasLimit);
}

public static SmartContractExecutionTransaction create(String from, String recipient, BigInteger amount,
byte[] payload, BigInteger gasPrice, BigInteger gasLimit) {
return new SmartContractExecutionTransaction(from, recipient, amount, payload, gasPrice, gasLimit);
}

public SmartContractExecutionTransaction feeRatio(BigInteger feeRatio) {
this.feeRatio = feeRatio;
return this;
Expand Down
Expand Up @@ -60,6 +60,12 @@ public TransactionTransformer(String from, BigInteger gasLimit) {
this.gasLimit = gasLimit;
}

public TransactionTransformer(String from, BigInteger gasPrice, BigInteger gasLimit) {
this.from = from;
this.gasLimit = gasLimit;
this.gasPrice = gasPrice;
}

public BigInteger getNonce() {
return nonce;
}
Expand Down
Expand Up @@ -33,10 +33,20 @@ private ValueTransferTransaction(String from, String to, BigInteger amount, BigI
this.amount = amount;
}

private ValueTransferTransaction(String from, String to, BigInteger amount, BigInteger gasPrice, BigInteger gasLimit) {
super(from, gasPrice, gasLimit);
this.to = to;
this.amount = amount;
}

public static ValueTransferTransaction create(String from, String to, BigInteger amount, BigInteger gasLimit) {
return new ValueTransferTransaction(from, to, amount, gasLimit);
}

public static ValueTransferTransaction create(String from, String to, BigInteger amount, BigInteger gasPrice, BigInteger gasLimit) {
return new ValueTransferTransaction(from, to, amount, gasPrice, gasLimit);
}

public ValueTransferTransaction memo(String memo) {
this.memo = memo.getBytes();
return this;
Expand Down

0 comments on commit 065bb1e

Please sign in to comment.