Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solution: JSON mapping for Blob related fields #74

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@ public class BlockJson<T extends TransactionRefJson> implements Serializable {

private List<WithdrawalJson> withdrawals;

@JsonDeserialize(using = HexLongDeserializer.class)
@JsonSerialize(using = HexLongSerializer.class)
private Long blobGasUsed;

@JsonDeserialize(using = HexLongDeserializer.class)
@JsonSerialize(using = HexLongSerializer.class)
private Long excessBlobGas;

private Hex32 parentBeaconBlockRoot;

public Long getNumber() {
return number;
}
Expand Down Expand Up @@ -375,6 +385,30 @@ public void setWithdrawals(List<WithdrawalJson> withdrawals) {
this.withdrawals = withdrawals;
}

public Long getBlobGasUsed() {
return blobGasUsed;
}

public void setBlobGasUsed(Long blobGasUsed) {
this.blobGasUsed = blobGasUsed;
}

public Long getExcessBlobGas() {
return excessBlobGas;
}

public void setExcessBlobGas(Long excessBlobGas) {
this.excessBlobGas = excessBlobGas;
}

public Hex32 getParentBeaconBlockRoot() {
return parentBeaconBlockRoot;
}

public void setParentBeaconBlockRoot(Hex32 parentBeaconBlockRoot) {
this.parentBeaconBlockRoot = parentBeaconBlockRoot;
}

/**
* If this instance is empty or contains only references, then return as is. Otherwise
* returns a copy of the BlockJson with transactions fields replaced with id references
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ public class TransactionJson extends TransactionRefJson implements TransactionRe

private List<Access> accessList;

private Wei maxFeePerBlobGas;

private List<Hex32> blobVersionedHashes;

public Long getNonce() {
return nonce;
}
Expand Down Expand Up @@ -280,6 +284,22 @@ public void setAccessList(List<Access> accessList) {
this.accessList = accessList;
}

public Wei getMaxFeePerBlobGas() {
return maxFeePerBlobGas;
}

public void setMaxFeePerBlobGas(Wei maxFeePerBlobGas) {
this.maxFeePerBlobGas = maxFeePerBlobGas;
}

public List<Hex32> getBlobVersionedHashes() {
return blobVersionedHashes;
}

public void setBlobVersionedHashes(List<Hex32> blobVersionedHashes) {
this.blobVersionedHashes = blobVersionedHashes;
}

public void addAccess(Access access) {
if (this.accessList == null) {
this.accessList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
import io.emeraldpay.etherjar.domain.BlockHash
import io.emeraldpay.etherjar.domain.TransactionId
import io.emeraldpay.etherjar.domain.Wei
import io.emeraldpay.etherjar.hex.Hex32
import io.emeraldpay.etherjar.rpc.JacksonRpcConverter
import spock.lang.Specification

Expand Down Expand Up @@ -386,4 +387,37 @@ class BlockJsonSpec extends Specification {
act.hash.toHex() == '0xa0437cab40119e21bc92d1ce5be52c89c64fa3b914489d51b4fe209a33ed31a5'
act.transactions == null
}

def "Parse with blobs info"() {
InputStream json = BlockJsonSpec.classLoader.getResourceAsStream("block/block-19443068.json")

when:
def act = jacksonRpcConverter.objectMapper.readValue(json, BlockJson)

then:
act instanceof BlockJson
act.hash.toHex() == '0x4d9557d1933a02fb780063b4c35c0cd9fb590014f851f50641befa034dbdc7e4'
act.blobGasUsed == 0xc0000
act.excessBlobGas == 0x60000
act.parentBeaconBlockRoot.toHex() == "0x7c132a0e0eef72627f2af7c994e8c3cf27c5e6d296473124fb270023db9cf81d"
}

def "Parse with blobs info and transactions"() {
InputStream json = BlockJsonSpec.classLoader.getResourceAsStream("block/block-19443105-full.json")

when:
BlockJson<TransactionJson> act = jacksonRpcConverter.objectMapper.readValue(json, BlockJson)

then:
act instanceof BlockJson
act.hash.toHex() == '0x52806b8fab72317f97413323cc739de2cd2afc5915298a24beed5d184d798d4b'
act.blobGasUsed == 0x60000
act.excessBlobGas == 0x0
with((TransactionJson)act.transactions.find { it.hash == TransactionId.from("0x109332e227bb505e5731fcbe231dc8d9c0136c14300cd34e40097abf72c51105") }) {
maxFeePerBlobGas == Wei.fromHex("0x22ecb25c00")
blobVersionedHashes == [
Hex32.from("0x01ebcede241d2473b6b1a6fa08f0a281858bc8901f742a39ff74d371e2f2664f")
]
}
}
}
Loading
Loading