Skip to content

Commit

Permalink
Merge pull request #154 from Juneo-io/dev
Browse files Browse the repository at this point in the history
v0.0.120
  • Loading branch information
alekswaslet authored Jul 11, 2024
2 parents e83a68f + ecd7f32 commit 0379d48
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 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.119",
"version": "0.0.120",
"description": "Juneo JS Library",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
25 changes: 12 additions & 13 deletions src/utils/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { type AbstractUtxoAPI } from '../api'
import { type MCNProvider } from '../juneo'
import {
AddPermissionlessDelegatorTransaction,
Expand All @@ -12,6 +11,7 @@ import {
CreateChainTransactionTypeId,
CreateSupernetTransaction,
CreateSupernetTransactionTypeId,
type ExportTransaction,
ImportTransaction,
JVMBaseTransaction,
JVMBaseTransactionTypeId,
Expand All @@ -26,7 +26,6 @@ import {
PlatformImportTransaction,
PlatformImportTransactionTypeId,
RemoveSupernetTransactionTypeId,
type TransferableInput,
TransferSupernetOwnershipTransactionTypeId,
TransformSupernetTransactionTypeId,
Utxo,
Expand All @@ -52,22 +51,22 @@ export class TransactionUtils {
static async syncUtxos (provider: MCNProvider, unsignedTx: UnsignedTransaction): Promise<void> {
const chain = getBlockchain(provider, unsignedTx.blockchainId)
const api = getUtxoAPI(provider, chain)
await TransactionUtils.syncInputUtxos(api, unsignedTx.inputs)
if (unsignedTx instanceof ImportTransaction) {
const importTx = unsignedTx
const sourceChain = getBlockchain(provider, importTx.sourceChain)
const sourceApi = getUtxoAPI(provider, sourceChain)
await TransactionUtils.syncInputUtxos(sourceApi, importTx.importedInputs)
}
}

static async syncInputUtxos (api: AbstractUtxoAPI, inputs: TransferableInput[]): Promise<void> {
for (const input of inputs) {
for (const input of unsignedTx.inputs) {
const data = (await api.getTx(input.transactionId.value)).tx
const tx = TransactionUtils.parseUnsignedTransaction(data)
const output = tx.outputs[input.utxoIndex]
input.input.utxo = new Utxo(input.transactionId, input.utxoIndex, input.assetId, output.output)
}
if (unsignedTx instanceof ImportTransaction) {
const sourceChain = getBlockchain(provider, unsignedTx.sourceChain)
const sourceApi = getUtxoAPI(provider, sourceChain)
for (const input of unsignedTx.importedInputs) {
const data = (await sourceApi.getTx(input.transactionId.value)).tx
const exportTx = TransactionUtils.parseUnsignedTransaction(data) as ExportTransaction
const output = exportTx.exportedOutputs[input.utxoIndex]
input.input.utxo = new Utxo(input.transactionId, input.utxoIndex, input.assetId, output.output)
}
}
}

static getTypeIdName (typeId: number): string {
Expand Down

0 comments on commit 0379d48

Please sign in to comment.