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

util: rename withdrawal request's validatorPublicKey to validatorPubkey #3474

Merged
merged 1 commit into from
Jun 27, 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
4 changes: 2 additions & 2 deletions packages/block/src/from-beacon-payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type BeaconDepositRequest = {

type BeaconWithdrawalRequest = {
source_address: PrefixedHexString
validator_public_key: PrefixedHexString
validator_pub_key: PrefixedHexString
amount: PrefixedHexString
}

Expand Down Expand Up @@ -160,7 +160,7 @@ export function executionPayloadFromBeaconPayload(payload: BeaconPayloadJson): E
if (payload.withdrawal_requests !== undefined && payload.withdrawal_requests !== null) {
executionPayload.withdrawalRequests = payload.withdrawal_requests.map((breq) => ({
sourceAddress: breq.source_address,
validatorPublicKey: breq.validator_public_key,
validatorPubkey: breq.validator_pub_key,
amount: breq.amount,
}))
}
Expand Down
2 changes: 1 addition & 1 deletion packages/block/test/eip7685block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function getRandomDepositRequest(): CLRequest<CLRequestType> {
function getRandomWithdrawalRequest(): CLRequest<CLRequestType> {
const withdrawalRequestData = {
sourceAddress: randomBytes(20),
validatorPublicKey: randomBytes(48),
validatorPubkey: randomBytes(48),
amount: bytesToBigInt(randomBytes(8)),
}
return WithdrawalRequest.fromRequestData(withdrawalRequestData) as CLRequest<CLRequestType>
Expand Down
6 changes: 3 additions & 3 deletions packages/client/src/rpc/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ export const validators = {
},

get withdrawalRequest() {
return (requiredFields: string[] = ['sourceAddress', 'validatorPublicKey', 'amount']) => {
return (requiredFields: string[] = ['sourceAddress', 'validatorPubkey', 'amount']) => {
return (params: any[], index: number) => {
if (typeof params[index] !== 'object') {
return {
Expand Down Expand Up @@ -517,8 +517,8 @@ export const validators = {
if (v !== undefined) return v
}

// validate validatorPublicKey
for (const field of [wt.validatorPublicKey]) {
// validate validatorPubkey
for (const field of [wt.validatorPubkey]) {
const v = validate(field, this.bytes48)
if (v !== undefined) return v
}
Expand Down
22 changes: 11 additions & 11 deletions packages/util/src/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type DepositRequestV1 = {

export type WithdrawalRequestV1 = {
sourceAddress: PrefixedHexString // DATA 20 bytes
validatorPublicKey: PrefixedHexString // DATA 48 bytes
validatorPubkey: PrefixedHexString // DATA 48 bytes
amount: PrefixedHexString // QUANTITY 8 bytes in gwei
}

Expand All @@ -49,7 +49,7 @@ export type DepositRequestData = {

export type WithdrawalRequestData = {
sourceAddress: Uint8Array
validatorPublicKey: Uint8Array
validatorPubkey: Uint8Array
amount: bigint
}

Expand Down Expand Up @@ -140,22 +140,22 @@ export class DepositRequest extends CLRequest<CLRequestType.Deposit> {
export class WithdrawalRequest extends CLRequest<CLRequestType.Withdrawal> {
constructor(
public readonly sourceAddress: Uint8Array,
public readonly validatorPublicKey: Uint8Array,
public readonly validatorPubkey: Uint8Array,
public readonly amount: bigint
) {
super(CLRequestType.Withdrawal)
}

public static fromRequestData(withdrawalData: WithdrawalRequestData): WithdrawalRequest {
const { sourceAddress, validatorPublicKey, amount } = withdrawalData
return new WithdrawalRequest(sourceAddress, validatorPublicKey, amount)
const { sourceAddress, validatorPubkey, amount } = withdrawalData
return new WithdrawalRequest(sourceAddress, validatorPubkey, amount)
}

public static fromJSON(jsonData: WithdrawalRequestV1): WithdrawalRequest {
const { sourceAddress, validatorPublicKey, amount } = jsonData
const { sourceAddress, validatorPubkey, amount } = jsonData
return this.fromRequestData({
sourceAddress: hexToBytes(sourceAddress),
validatorPublicKey: hexToBytes(validatorPublicKey),
validatorPubkey: hexToBytes(validatorPubkey),
amount: hexToBigInt(amount),
})
}
Expand All @@ -165,27 +165,27 @@ export class WithdrawalRequest extends CLRequest<CLRequestType.Withdrawal> {

return concatBytes(
Uint8Array.from([this.type]),
RLP.encode([this.sourceAddress, this.validatorPublicKey, amountBytes])
RLP.encode([this.sourceAddress, this.validatorPubkey, amountBytes])
)
}

toJSON(): WithdrawalRequestV1 {
return {
sourceAddress: bytesToHex(this.sourceAddress),
validatorPublicKey: bytesToHex(this.validatorPublicKey),
validatorPubkey: bytesToHex(this.validatorPubkey),
amount: bigIntToHex(this.amount),
}
}

public static deserialize(bytes: Uint8Array): WithdrawalRequest {
const [sourceAddress, validatorPublicKey, amount] = RLP.decode(bytes.slice(1)) as [
const [sourceAddress, validatorPubkey, amount] = RLP.decode(bytes.slice(1)) as [
Uint8Array,
Uint8Array,
Uint8Array
]
return this.fromRequestData({
sourceAddress,
validatorPublicKey,
validatorPubkey,
amount: bytesToBigInt(amount),
})
}
Expand Down
2 changes: 1 addition & 1 deletion packages/util/test/requests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Requests', () => {
it('withdrawal request', () => {
const withdrawalRequestData = {
sourceAddress: randomBytes(20),
validatorPublicKey: randomBytes(48),
validatorPubkey: randomBytes(48),
amount: bytesToBigInt(randomBytes(8)),
}

Expand Down
6 changes: 2 additions & 4 deletions packages/vm/src/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,9 @@ const accumulateEIP7002Requests = async (
for (let startByte = 0; startByte < resultsBytes.length; startByte += 76) {
const slicedBytes = resultsBytes.slice(startByte, startByte + 76)
const sourceAddress = slicedBytes.slice(0, 20) // 20 Bytes
const validatorPublicKey = slicedBytes.slice(20, 68) // 48 Bytes
const validatorPubkey = slicedBytes.slice(20, 68) // 48 Bytes
const amount = bytesToBigInt(unpadBytes(slicedBytes.slice(68, 76))) // 8 Bytes / Uint64
requests.push(
WithdrawalRequest.fromRequestData({ sourceAddress, validatorPublicKey, amount })
)
requests.push(WithdrawalRequest.fromRequestData({ sourceAddress, validatorPubkey, amount }))
}
}

Expand Down
Loading