Skip to content

Commit

Permalink
messages: update block proto according to LIP1
Browse files Browse the repository at this point in the history
see #86
  • Loading branch information
VandeurenGlenn committed Apr 29, 2024
1 parent 8b9470d commit fe9e1ac
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions packages/messages/src/messages/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,22 @@ export default class BlockMessage extends FormatInterface {
encode(decoded?): Uint8Array {
decoded = decoded || this.decoded
const validators: Uint8Array[] = []
const transactions: Uint8Array[] = []

for (const validator of decoded.validators) {
if (validator instanceof ValidatorMessage) validators.push(validator.encode())
else validators.push(new ValidatorMessage(validator).encode())
}

for (const transaction of decoded.transactions) {
if (transaction instanceof TransactionMessage) transactions.push(transaction.encode())
else transactions.push(new TransactionMessage(transaction).encode())
}

return super.encode({
...decoded,
validators: smartConcat(validators),
transactions: smartConcat(transactions)
validators: smartConcat(validators)
})
}

decode(encoded?) {
encoded = encoded || this.encoded
super.decode(encoded)
// @ts-ignore
this.decoded.transactions = smartDeconcat(this.decoded.transactions as Uint8Array).map(
(transaction) => new TransactionMessage(transaction).decoded
)
// @ts-ignore
this.decoded.validators = smartDeconcat(this.decoded.validators as Uint8Array).map(
(validator) => new ValidatorMessage(validator).decoded
)
Expand Down

0 comments on commit fe9e1ac

Please sign in to comment.