Skip to content

Commit

Permalink
Merge pull request #155 from Juneo-io/dev
Browse files Browse the repository at this point in the history
v0.0.121
  • Loading branch information
alekswaslet authored Jul 11, 2024
2 parents 0379d48 + cec4e3c commit 9a3e5aa
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/transaction/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions src/transaction/platform/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
PlatformExportTransactionTypeId,
PlatformImportTransactionTypeId,
PrimarySignerSize,
RemoveSupernetTransactionTypeId,
RemoveSupernetValidatorTransactionTypeId,
SupernetIdSize,
TransferSupernetOwnershipTransactionTypeId,
TransformSupernetTransactionTypeId,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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[] = []
Expand Down
20 changes: 19 additions & 1 deletion src/transaction/transaction.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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<Signature[]>
signTransaction: (signers: Signer[]) => Promise<string>
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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[] = []
Expand Down
10 changes: 5 additions & 5 deletions src/utils/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
CreateChainTransactionTypeId,
CreateSupernetTransaction,
CreateSupernetTransactionTypeId,
type ExportTransaction,
ImportTransaction,
JVMBaseTransaction,
JVMBaseTransactionTypeId,
Expand All @@ -25,10 +24,11 @@ import {
PlatformExportTransactionTypeId,
PlatformImportTransaction,
PlatformImportTransactionTypeId,
RemoveSupernetTransactionTypeId,
RemoveSupernetValidatorTransactionTypeId,
TransferSupernetOwnershipTransactionTypeId,
TransformSupernetTransactionTypeId,
Utxo,
type ExportTransaction,
type UnsignedTransaction
} from '../transaction'
import { JuneoBuffer } from './bytes'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -164,7 +164,7 @@ export class TransactionUtils {
case PlatformExportTransactionTypeId: {
return PlatformExportTransaction.parse(data)
}
case RemoveSupernetTransactionTypeId: {
case RemoveSupernetValidatorTransactionTypeId: {
throw notImplementedTypeIdError
}
case TransformSupernetTransactionTypeId: {
Expand Down

0 comments on commit 9a3e5aa

Please sign in to comment.