-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
Summary
At the moment we have built a "generic rlp encoding solution" and then applied it to a vechain transaction
And we have made use of dependency @ethereumjs/rlp to do that
We also expose publicly RLP classes that really users won't need
The objective is to simplify this, we do not need a general rlp encoding solution, only something that is specific to encode vechain transaction / decode vechain transaction. We can make use of viem dependency for this and remove the @ethereumjs/rlp dependency
Rough design (for encoding):
Helpers:
import { toHex, type Hex } from 'viem'
type RlpPrimitive =
| Hex
| number
| bigint
| null
| undefined
export function toRlpValue(value: RlpPrimitive): Hex {
if (value === null || value === undefined) return '0x'
if (typeof value === 'number' || typeof value === 'bigint') {
const v = BigInt(value)
return v === 0n ? '0x' : toHex(v)
}
// Hex string → raw bytes
return value
}
Usage:
const clause = [
toRlpValue(c.to),
toRlpValue(c.value),
toRlpValue(c.data),
]
const body = [
toRlpValue(tx.chainTag),
toRlpValue(tx.blockRef),
toRlpValue(tx.expiration),
clauses,
toRlpValue(tx.gasPriceCoef),
toRlpValue(tx.gas),
toRlpValue(tx.dependsOn),
toRlpValue(tx.nonce),
tx.reserved ?? [],
]
const encoded = toRlp(body)
Basic Example
a
Reactions are currently unavailable