Skip to content

Commit

Permalink
Support for conflux hardfork 2.4.0 (#52)
Browse files Browse the repository at this point in the history
* support conflux-rust 2.4 rpc changes

* support for 1559 transaction type

* remove log
  • Loading branch information
Pana authored Jul 2, 2024
1 parent d2fe4fb commit c3ccf54
Show file tree
Hide file tree
Showing 14 changed files with 503 additions and 13 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

### 1.3.0

This version add support for [Conflux hardfork v2.4.0](https://doc.confluxnetwork.org/docs/general/hardforks/v2.4), including:

1. New added RPC methods: cfx_maxPriorityFeePerGas, cfx_feeHistory, cfx_getFeeBurnt
2. Support for CIP-1559 transaction

### 1.2.10

1. Fix SendTransactionError parse method to handle data is null
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {
}

group = 'io.github.conflux-chain'
version = '1.2.10' // SNAPSHOT
version = '1.3.0' // SNAPSHOT

repositories {
jcenter()
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/conflux/web3j/Cfx.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ static Cfx create(Web3jService service, int retry, long intervalMillis) {
BigInteger getChainId();

Request<BigInteger, BigIntResponse> getGasPrice();

Request<BigInteger, BigIntResponse> getMaxPriorityFeePerGas();

Request<BigInteger, BigIntResponse> getFeeBurnt();

Request<BigInteger, BigIntResponse> getEpochNumber(Epoch... epoch);

Expand Down Expand Up @@ -128,6 +132,10 @@ static Cfx create(Web3jService service, int retry, long intervalMillis) {

Request<PoSEpochRewards, PoSEpochRewards.Response> getPoSRewardByEpoch(Address address, Epoch epoch);

Request<ParamsOfVote, ParamsOfVote.Response> getParamsFromVote(Epoch... epoch);

Request<FeeHistory, FeeHistory.Response> getFeeHistory(int count, Epoch epoch, List<Float> percentiles);

<T,R extends Response<?> & HasValue<T>> Request<T, R> getCustomizedRequest(Class<R> responseType, String method, Object... params);

default Receipt waitForReceipt(String txHash) throws InterruptedException {
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/conflux/web3j/Web3j.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@ public Request<BigInteger, BigIntResponse> getGasPrice() {
.withRetry(this.retry, this.intervalMillis);
}

@Override
public Request<BigInteger, BigIntResponse> getMaxPriorityFeePerGas() {
return new Request<>(this.service, "cfx_maxPriorityFeePerGas", BigIntResponse.class)
.withRetry(this.retry, this.intervalMillis);
}

@Override
public Request<BigInteger, BigIntResponse> getFeeBurnt() {
return new Request<>(this.service, "cfx_getFeeBurnt", BigIntResponse.class)
.withRetry(this.retry, this.intervalMillis);
}

@Override
public Request<FeeHistory, FeeHistory.Response> getFeeHistory(int count, Epoch epoch, List<Float> percentiles) {
return new Request<>(this.service, "cfx_feeHistory", FeeHistory.Response.class, count, epoch.getValue(), percentiles)
.withRetry(this.retry, this.intervalMillis);
}

@Override
public Request<BigInteger, BigIntResponse> getEpochNumber(Epoch... epoch) {
if (epoch.length == 0) {
Expand All @@ -83,6 +101,17 @@ public Request<BigInteger, BigIntResponse> getEpochNumber(Epoch... epoch) {
}
}

@Override
public Request<ParamsOfVote, ParamsOfVote.Response> getParamsFromVote(Epoch... epoch) {
if (epoch.length == 0) {
return new Request<>(this.service, "cfx_getParamsFromVote", ParamsOfVote.Response.class)
.withRetry(this.retry, this.intervalMillis);
} else {
return new Request<>(this.service, "cfx_getParamsFromVote", ParamsOfVote.Response.class, epoch[0].getValue())
.withRetry(this.retry, this.intervalMillis);
}
}

@Override
public Request<BigInteger, BigIntResponse> getBalance(Address address, Epoch... epoch) {
if (epoch.length == 0) {
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/conflux/web3j/request/Call.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package conflux.web3j.request;

import java.math.BigInteger;

import conflux.web3j.types.AccessListEntry;
import conflux.web3j.types.Address;
import org.web3j.utils.Numeric;
import java.util.List;

public class Call {
private Address from;
Expand All @@ -13,6 +16,10 @@ public class Call {
private String data;
private BigInteger nonce;
private BigInteger storageLimit;
private BigInteger type;
private BigInteger maxFeePerGas;
private BigInteger maxPriorityFeePerGas;
private List<AccessListEntry> accessList;

public Address getFrom() {
return from;
Expand All @@ -33,6 +40,38 @@ public void setTo(Address to) {
public String getGasPrice() {
return this.gasPrice == null ? null : Numeric.encodeQuantity(this.gasPrice);
}

public String getMaxFeePerGas() {
return this.maxFeePerGas == null ? null : Numeric.encodeQuantity(this.maxFeePerGas);
}

public void setMaxFeePerGas(BigInteger maxFeePerGas) {
this.maxFeePerGas = maxFeePerGas;
}

public String getMaxPriorityFeePerGas() {
return this.maxPriorityFeePerGas == null ? null : Numeric.encodeQuantity(this.maxPriorityFeePerGas);
}

public void setMaxPriorityFeePerGas(BigInteger maxPriorityFeePerGas) {
this.maxPriorityFeePerGas = maxPriorityFeePerGas;
}

public void setType(BigInteger type) {
this.type = type;
}

public String getType() {
return this.type == null ? null : Numeric.encodeQuantity(this.type);
}

public List<AccessListEntry> getAccessList() {
return accessList;
}

public void setAccessList(List<AccessListEntry> accessList) {
this.accessList = accessList;
}

public void setGasPrice(BigInteger gasPrice) {
this.gasPrice = gasPrice;
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/conflux/web3j/response/BlockHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ public class BlockHeader {
private String size;
private String posReference;
private List<String> custom;
private String baseFeePerGas;

public BigInteger getBaseFeePerGas() {
return Numeric.decodeQuantity(this.baseFeePerGas);
}

public void setBaseFeePerGas(String baseFeePerGas) {
this.baseFeePerGas = baseFeePerGas;
}

public String getHash() {
return hash;
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/conflux/web3j/response/FeeHistory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package conflux.web3j.response;
import org.web3j.utils.Numeric;

import java.math.BigInteger;
import java.util.List;
import java.util.stream.Collectors;

public class FeeHistory {
public static class Response extends CfxResponse<FeeHistory> {}

private String oldestEpoch;
private List<String> baseFeePerGas;
private List<Float> gasUsedRatio;
private List<String> reward;

public BigInteger getOldestEpoch() {
return Numeric.decodeQuantity(oldestEpoch);
}

public void setOldestEpoch(String oldestEpoch) {
this.oldestEpoch = oldestEpoch;
}

public List<BigInteger> getBaseFeePerGas() {
return baseFeePerGas.stream().map(Numeric::decodeQuantity).collect(Collectors.toList());
}

public void setBaseFeePerGas(List<String> baseFeePerGas) {
this.baseFeePerGas = baseFeePerGas;
}

public List<Float> getGasUsedRatio() {
return gasUsedRatio;
}

public void setGasUsedRatio(List<Float> gasUsedRatio) {
this.gasUsedRatio = gasUsedRatio;
}

public List<BigInteger> getReward() {
return reward.stream().map(Numeric::decodeQuantity).collect(Collectors.toList());
}

public void setReward(List<String> reward) {
this.reward = reward;
}
}
46 changes: 46 additions & 0 deletions src/main/java/conflux/web3j/response/ParamsOfVote.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package conflux.web3j.response;

import org.web3j.utils.Numeric;

import java.math.BigInteger;

public class ParamsOfVote {
public static class Response extends CfxResponse<ParamsOfVote> {}

private String baseFeeShareProp;
private String interestRate;
private String powBaseReward;
private String storagePointProp;

public BigInteger getBaseFeeShareProp() {
return Numeric.decodeQuantity(baseFeeShareProp);
}

public void setBaseFeeShareProp(String baseFeeShareProp) {
this.baseFeeShareProp = baseFeeShareProp;
}

public BigInteger getInterestRate() {
return Numeric.decodeQuantity(interestRate);
}

public void setInterestRate(String interestRate) {
this.interestRate = interestRate;
}

public BigInteger getPowBaseReward() {
return Numeric.decodeQuantity(powBaseReward);
}

public void setPowBaseReward(String powBaseReward) {
this.powBaseReward = powBaseReward;
}

public BigInteger getStoragePointProp() {
return Numeric.decodeQuantity(storagePointProp);
}

public void setStoragePointProp(String storagePointProp) {
this.storagePointProp = storagePointProp;
}
}
30 changes: 30 additions & 0 deletions src/main/java/conflux/web3j/response/Receipt.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,33 @@ public static class ListResponse extends CfxNullableResponse<List<List<Receipt>>
private String storageCollateralized;
private List<StorageChange> storageReleased;
private String gasFee;
private String type;
private String burntGasFee;
private String effectiveGasPrice;

public BigInteger getBurntGasFee() {
return Numeric.decodeQuantity(burntGasFee);
}

public void setBurntGasFee(String burntGasFee) {
this.burntGasFee = burntGasFee;
}

public BigInteger getEffectiveGasPrice() {
return Numeric.decodeQuantity(effectiveGasPrice);
}

public void setEffectiveGasPrice(String effectiveGasPrice) {
this.effectiveGasPrice = effectiveGasPrice;
}

public int getType() {
return Numeric.decodeQuantity(type).intValue();
}

public void setType(String type) {
this.type = type;
}

public String getTransactionHash() {
return transactionHash;
Expand Down Expand Up @@ -177,4 +203,8 @@ public void setStorageReleased(List<StorageChange> change) {
public BigInteger getGasFee(){
return Numeric.decodeQuantity(gasFee);
}

public void setGasFee(String gasFee) {
this.gasFee = gasFee;
}
}
47 changes: 47 additions & 0 deletions src/main/java/conflux/web3j/response/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import java.math.BigInteger;
import java.util.Optional;

import conflux.web3j.types.AccessListEntry;
import conflux.web3j.types.Address;
import org.web3j.utils.Numeric;
import java.util.List;

public class Transaction {

Expand All @@ -28,6 +30,51 @@ public static class Response extends CfxNullableResponse<Transaction> {}
private String v;
private String r;
private String s;
private String type;
private String yParity;
private String maxFeePerGas;
private String maxPriorityFeePerGas;
private List<AccessListEntry> accessList;

public BigInteger getMaxFeePerGas() {
return Numeric.decodeQuantity(this.maxFeePerGas);
}

public void setMaxFeePerGas(String maxFeePerGas) {
this.maxFeePerGas = maxFeePerGas;
}

public BigInteger getMaxPriorityFeePerGas() {
return Numeric.decodeQuantity(this.maxPriorityFeePerGas);
}

public void setMaxPriorityFeePerGas(String maxPriorityFeePerGas) {
this.maxPriorityFeePerGas = maxPriorityFeePerGas;
}

public BigInteger getYParity() {
return Numeric.decodeQuantity(yParity);
}

public void setYParity(String yParity) {
this.yParity = yParity;
}

public int getType() {
return Numeric.decodeQuantity(type).intValue();
}

public void setType(String type) {
this.type = type;
}

public List<AccessListEntry> getAccessList() {
return accessList;
}

public void setAccessList(List<AccessListEntry> accessList) {
this.accessList = accessList;
}

public String getHash() {
return hash;
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/conflux/web3j/types/AccessListEntry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package conflux.web3j.types;
import java.util.List;

public class AccessListEntry {

private Address address;
private List<String> storageKeys;

public List<String> getStorageKeys() {
return storageKeys;
}

public void setStorageKeys(List<String> storageKeys) {
this.storageKeys = storageKeys;
}

public Address getAddress() {
return address;
}

public void setAddress(CfxAddress address) {
this.address = address;
}
}
Loading

0 comments on commit c3ccf54

Please sign in to comment.