@emurgo/yoroi-lib-core
Advanced tools
Comparing version 0.1.4-alpha.19 to 0.1.5-alpha.20
import { BigNumber } from 'bignumber.js'; | ||
import { AddressingAddress, AddressingUtxo, CardanoHaskellConfig, SendToken, Token, TxOptions } from './internals/models'; | ||
import { AddressingAddress, CardanoAddressedUtxo, CardanoHaskellConfig, SendToken, Token, TxOptions } from './internals/models'; | ||
import { UnsignedTx } from './internals/tx'; | ||
@@ -26,3 +26,3 @@ import * as WasmContract from './internals/wasm-contract'; | ||
decryptWithPassword(password: string, data: string): Promise<string>; | ||
createUnsignedTx(absSlotNumber: BigNumber, utxos: Array<AddressingUtxo>, receiver: string, changeAddr: AddressingAddress, tokens: Array<SendToken>, config: CardanoHaskellConfig, defaultToken: Token, txOptions: TxOptions): Promise<UnsignedTx>; | ||
createUnsignedTx(absSlotNumber: BigNumber, utxos: Array<CardanoAddressedUtxo>, receiver: string, changeAddr: AddressingAddress, tokens: Array<SendToken>, config: CardanoHaskellConfig, defaultToken: Token, txOptions: TxOptions): Promise<UnsignedTx>; | ||
} |
@@ -94,3 +94,2 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const addressedUtxo = yield (0, transactions_1.asAddressedUtxo)(this.Wasm, utxos); | ||
const receivers = [ | ||
@@ -104,3 +103,3 @@ { | ||
} | ||
return yield this.createUnsignedTxForUtxos(absSlotNumber, receivers, defaultToken, tokens, addressedUtxo, config, txOptions); | ||
return yield this.createUnsignedTxForUtxos(absSlotNumber, receivers, defaultToken, tokens, utxos, config, txOptions); | ||
}); | ||
@@ -107,0 +106,0 @@ } |
@@ -19,5 +19,2 @@ import { BigNumber } from 'bignumber.js'; | ||
}; | ||
export declare type AddressingUtxo = AddressingAddress & { | ||
output: Utxo; | ||
}; | ||
export declare type CardanoAddressedUtxo = RemoteUnspentOutput & { | ||
@@ -24,0 +21,0 @@ addressing: Addressing; |
import * as WasmContract from '../wasm-contract'; | ||
import { AddressingAddress, AddressingUtxo, CardanoAddressedUtxo, RemoteUnspentOutput } from '../models'; | ||
import { AddressingAddress, RemoteUnspentOutput } from '../models'; | ||
import { AddInputResult } from './index'; | ||
@@ -15,3 +15,2 @@ export declare function minRequiredForChange(wasm: WasmContract.WasmModuleProxy, txBuilder: WasmContract.TransactionBuilder, changeAdaAddr: AddressingAddress, value: WasmContract.Value, protocolParams: { | ||
export declare function cardanoValueFromRemoteFormat(wasm: WasmContract.WasmModuleProxy, utxo: RemoteUnspentOutput): Promise<WasmContract.Value>; | ||
export declare function asAddressedUtxo(wasm: WasmContract.WasmModuleProxy, utxos: Array<AddressingUtxo>): Promise<Array<CardanoAddressedUtxo>>; | ||
export declare function isBigNumZero(wasm: WasmContract.WasmModuleProxy, b: WasmContract.BigNum): Promise<boolean>; |
@@ -12,3 +12,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isBigNumZero = exports.asAddressedUtxo = exports.cardanoValueFromRemoteFormat = exports.addUtxoInput = exports.minRequiredForChange = void 0; | ||
exports.isBigNumZero = exports.cardanoValueFromRemoteFormat = exports.addUtxoInput = exports.minRequiredForChange = void 0; | ||
const models_1 = require("../models"); | ||
@@ -144,43 +144,2 @@ const addresses_1 = require("./addresses"); | ||
exports.cardanoValueFromRemoteFormat = cardanoValueFromRemoteFormat; | ||
function asAddressedUtxo(wasm, utxos) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield Promise.all(utxos.map((utxo) => __awaiter(this, void 0, void 0, function* () { | ||
const tokenTypes = utxo.output.tokens.reduce((acc, next) => { | ||
if (next.token.identifier === models_1.PRIMARY_ASSET_CONSTANTS.Cardano) { | ||
acc.amount = acc.amount.plus(next.amount); | ||
} | ||
else { | ||
acc.tokens.push({ | ||
amount: next.amount, | ||
tokenId: next.token.identifier | ||
}); | ||
} | ||
return acc; | ||
}, { | ||
amount: new bignumber_js_1.BigNumber(0), | ||
tokens: [] | ||
}); | ||
const assets = yield Promise.all(tokenTypes.tokens.map((token) => __awaiter(this, void 0, void 0, function* () { | ||
const pieces = yield (0, assets_1.identifierToCardanoAsset)(wasm, token.tokenId); | ||
return { | ||
amount: token.amount, | ||
assetId: token.tokenId, | ||
policyId: Buffer.from(yield pieces.policyId.toBytes()).toString('hex'), | ||
name: Buffer.from(yield pieces.name.name()).toString('hex') | ||
}; | ||
}))); | ||
return { | ||
amount: tokenTypes.amount.toString(), | ||
receiver: utxo.address, | ||
txHash: utxo.output.transaction.hash, | ||
txIndex: utxo.output.index, | ||
utxoId: utxo.output.transaction.hash + | ||
utxo.output.index, | ||
addressing: utxo.addressing, | ||
assets | ||
}; | ||
}))); | ||
}); | ||
} | ||
exports.asAddressedUtxo = asAddressedUtxo; | ||
function utxoToTxInput(wasm, utxo) { | ||
@@ -187,0 +146,0 @@ return __awaiter(this, void 0, void 0, function* () { |
{ | ||
"name": "@emurgo/yoroi-lib-core", | ||
"version": "0.1.4-alpha.19", | ||
"version": "0.1.5-alpha.20", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
229580
4175