From b49d1cf02bfb5a3005e6036f42add921cb2ea764 Mon Sep 17 00:00:00 2001 From: alekswaslet <1346150+alekswaslet@users.noreply.github.com> Date: Thu, 11 Jul 2024 14:33:58 +0200 Subject: [PATCH 1/3] Fixed typo --- src/transaction/constants.ts | 2 +- src/transaction/platform/transaction.ts | 4 ++-- src/utils/transaction.ts | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/transaction/constants.ts b/src/transaction/constants.ts index 9c1cdb6..d253b32 100644 --- a/src/transaction/constants.ts +++ b/src/transaction/constants.ts @@ -33,7 +33,7 @@ export const CreateChainTransactionTypeId = 0x0000000f export const CreateSupernetTransactionTypeId = 0x00000010 export const PlatformImportTransactionTypeId = 0x00000011 export const PlatformExportTransactionTypeId = 0x00000012 -export const RemoveSupernetTransactionTypeId = 0x00000017 +export const RemoveSupernetValidatorTransactionTypeId = 0x00000017 export const TransformSupernetTransactionTypeId = 0x00000018 export const AddPermissionlessValidatorTransactionTypeId = 0x00000019 export const AddPermissionlessDelegatorTransactionTypeId = 0x0000001a diff --git a/src/transaction/platform/transaction.ts b/src/transaction/platform/transaction.ts index 594dd1e..fa79309 100644 --- a/src/transaction/platform/transaction.ts +++ b/src/transaction/platform/transaction.ts @@ -12,7 +12,7 @@ import { PlatformExportTransactionTypeId, PlatformImportTransactionTypeId, PrimarySignerSize, - RemoveSupernetTransactionTypeId, + RemoveSupernetValidatorTransactionTypeId, SupernetIdSize, TransferSupernetOwnershipTransactionTypeId, TransformSupernetTransactionTypeId, @@ -347,7 +347,7 @@ export class RemoveSupernetValidatorTransaction extends BaseTransaction { supernetId: SupernetId, supernetAuth: SupernetAuth ) { - super(RemoveSupernetTransactionTypeId, networkId, blockchainId, outputs, inputs, memo) + super(RemoveSupernetValidatorTransactionTypeId, networkId, blockchainId, outputs, inputs, memo) this.nodeId = nodeId this.supernetId = supernetId this.supernetAuth = supernetAuth diff --git a/src/utils/transaction.ts b/src/utils/transaction.ts index cc79559..789f767 100644 --- a/src/utils/transaction.ts +++ b/src/utils/transaction.ts @@ -11,7 +11,6 @@ import { CreateChainTransactionTypeId, CreateSupernetTransaction, CreateSupernetTransactionTypeId, - type ExportTransaction, ImportTransaction, JVMBaseTransaction, JVMBaseTransactionTypeId, @@ -25,10 +24,11 @@ import { PlatformExportTransactionTypeId, PlatformImportTransaction, PlatformImportTransactionTypeId, - RemoveSupernetTransactionTypeId, + RemoveSupernetValidatorTransactionTypeId, TransferSupernetOwnershipTransactionTypeId, TransformSupernetTransactionTypeId, Utxo, + type ExportTransaction, type UnsignedTransaction } from '../transaction' import { JuneoBuffer } from './bytes' @@ -102,8 +102,8 @@ export class TransactionUtils { case PlatformExportTransactionTypeId: { return 'Platform Export Transaction' } - case RemoveSupernetTransactionTypeId: { - return 'Remove Supernet Transaction' + case RemoveSupernetValidatorTransactionTypeId: { + return 'Remove Supernet Validator Transaction' } case TransformSupernetTransactionTypeId: { return 'Transform Supernet Transaction' @@ -164,7 +164,7 @@ export class TransactionUtils { case PlatformExportTransactionTypeId: { return PlatformExportTransaction.parse(data) } - case RemoveSupernetTransactionTypeId: { + case RemoveSupernetValidatorTransactionTypeId: { throw notImplementedTypeIdError } case TransformSupernetTransactionTypeId: { From 3f710a5ee64e9976d76df684010cc920e422cf5b Mon Sep 17 00:00:00 2001 From: alekswaslet <1346150+alekswaslet@users.noreply.github.com> Date: Thu, 11 Jul 2024 15:03:10 +0200 Subject: [PATCH 2/3] Added getOutputs and get output via index for unsignedTx --- src/transaction/platform/transaction.ts | 8 ++++++++ src/transaction/transaction.ts | 20 +++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/transaction/platform/transaction.ts b/src/transaction/platform/transaction.ts index fa79309..62d8e67 100644 --- a/src/transaction/platform/transaction.ts +++ b/src/transaction/platform/transaction.ts @@ -521,6 +521,10 @@ export class AddPermissionlessValidatorTransaction extends BaseTransaction { this.shares = shares } + getOutputs (): TransferableOutput[] { + return [...this.outputs, ...this.stake] + } + serialize (): JuneoBuffer { const baseTransaction: JuneoBuffer = super.serialize() const signerBytes: JuneoBuffer = this.signer.serialize() @@ -623,6 +627,10 @@ export class AddPermissionlessDelegatorTransaction extends BaseTransaction { this.delegatorRewardsOwner = delegatorRewardsOwner } + getOutputs (): TransferableOutput[] { + return [...this.outputs, ...this.stake] + } + serialize (): JuneoBuffer { const baseTransaction: JuneoBuffer = super.serialize() const stakeBytes: JuneoBuffer[] = [] diff --git a/src/transaction/transaction.ts b/src/transaction/transaction.ts index fa6335e..32f4211 100644 --- a/src/transaction/transaction.ts +++ b/src/transaction/transaction.ts @@ -1,5 +1,5 @@ import { type Blockchain } from '../chain' -import { JuneoBuffer, SignatureError, type Serializable } from '../utils' +import { JuneoBuffer, SignatureError, TransactionError, type Serializable } from '../utils' import { BlockchainIdSize, CodecId } from './constants' import { TransferableInput } from './input' import { TransferableOutput, type Utxo } from './output' @@ -32,6 +32,8 @@ export interface UnsignedTransaction extends Serializable { memo: string getSignables: () => Signable[] getInputs: () => TransferableInput[] + getOutputs: () => TransferableOutput[] + getOutput: (index: number) => TransferableOutput getUtxos: () => Utxo[] sign: (signers: Signer[]) => Promise signTransaction: (signers: Signer[]) => Promise @@ -73,6 +75,18 @@ export class BaseTransaction implements UnsignedTransaction { return this.inputs } + getOutputs (): TransferableOutput[] { + return this.outputs + } + + getOutput (index: number): TransferableOutput { + const outputs = this.getOutputs() + if (index > outputs.length) { + throw new TransactionError(`transaction does not have output at index ${index} > length (${outputs.length})`) + } + return outputs[index] + } + getUtxos (): Utxo[] { const utxos: Utxo[] = [] for (const transferable of this.inputs) { @@ -211,6 +225,10 @@ export class ExportTransaction extends BaseTransaction { this.exportedOutputs.sort(TransferableOutput.comparator) } + getOutputs (): TransferableOutput[] { + return [...this.outputs, ...this.exportedOutputs] + } + serialize (): JuneoBuffer { const baseTransaction: JuneoBuffer = super.serialize() const exportedOutputsBytes: JuneoBuffer[] = [] From cec4e3c4396a449bbf2a642856cecd2795cd9108 Mon Sep 17 00:00:00 2001 From: alekswaslet <1346150+alekswaslet@users.noreply.github.com> Date: Thu, 11 Jul 2024 15:09:12 +0200 Subject: [PATCH 3/3] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c3afa90..a9f8dbc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "juneojs", - "version": "0.0.120", + "version": "0.0.121", "description": "Juneo JS Library", "main": "dist/index.js", "types": "dist/index.d.ts",