Skip to content

Commit

Permalink
add the network serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech committed May 19, 2023
1 parent de40472 commit dd9da28
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/client/lib/net/protocol/ethprotocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,12 @@ export class EthProtocol extends Protocol {
return [
bytesToBigInt(reqId),
txs.map((txData) => {
// Blob transactions are deserialized with network wrapper
if (txData[0] === 5) {
// Blob transactions are deserialized with network wrapper
return BlobEIP4844Transaction.fromSerializedBlobTxNetworkWrapper(txData)
return BlobEIP4844Transaction.fromSerializedBlobTxNetworkWrapper(txData, { common })
} else {
return TransactionFactory.fromBlockBodyData(txData, { common })
}
return TransactionFactory.fromBlockBodyData(txData)
}),
]
},
Expand Down
21 changes: 21 additions & 0 deletions packages/tx/src/eip4844Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,27 @@ export class BlobEIP4844Transaction extends BaseTransaction<BlobEIP4844Transacti
return concatBytes(TRANSACTION_TYPE_BYTES, RLP.encode(base))
}

/**
* @returns the serialized form of a blob transaction in the network wrapper format (used for gossipping mempool transactions over devp2p)
*/
serializeNetworkWrapper(): Uint8Array {
if (
this.blobs === undefined ||
this.kzgCommitments === undefined ||
this.kzgProofs === undefined
) {
throw new Error(
'cannot serialize network wrapper without blobs, KZG commitments and KZG proofs provided'
)
}

const tx_payload = this.raw()
return concatBytes(
TRANSACTION_TYPE_BYTES,
RLP.encode([tx_payload, this.blobs, this.kzgCommitments, this.kzgProofs])
)
}

getMessageToSign(hashMessage = true): Uint8Array {
const base = this.raw().slice(0, 11)
const message = concatBytes(TRANSACTION_TYPE_BYTES, RLP.encode(base))
Expand Down

0 comments on commit dd9da28

Please sign in to comment.