@fivebinaries/coin-selection
Advanced tools
Comparing version 2.0.0-beta.8 to 2.0.0-beta.9
@@ -1,5 +0,5 @@ | ||
import { CoinSelectionParams, Options, PrecomposedTransaction } from './types/types'; | ||
export declare const coinSelection: (params: CoinSelectionParams, options?: Options | undefined) => PrecomposedTransaction; | ||
import { Certificate, Options, PrecomposedTransaction, UserOutput, Utxo, Withdrawal } from './types/types'; | ||
export declare const coinSelection: (utxos: Utxo[], outputs: UserOutput[], changeAddress: string, certificates: Certificate[], withdrawals: Withdrawal[], accountPubKey: string, options?: Options | undefined) => PrecomposedTransaction; | ||
export * as trezorUtils from './utils/trezor'; | ||
export * as types from './types/types'; | ||
export { CoinSelectionError } from './utils/errors'; |
@@ -28,9 +28,14 @@ "use strict"; | ||
const logger_1 = require("./utils/logger"); | ||
const coinSelection = (params, options) => { | ||
const coinSelection = (utxos, outputs, changeAddress, certificates, withdrawals, accountPubKey, options) => { | ||
const logger = (0, logger_1.getLogger)(!!(options === null || options === void 0 ? void 0 : options.debug)); | ||
logger.debug('Args:', { | ||
params, | ||
utxos, | ||
outputs, | ||
changeAddress, | ||
certificates, | ||
withdrawals, | ||
accountPubKey, | ||
options, | ||
}); | ||
if (params.utxos.length === 0) { | ||
if (utxos.length === 0) { | ||
logger.debug('Empty Utxo set'); | ||
@@ -41,8 +46,8 @@ throw new errors_1.CoinSelectionError(constants_1.ERROR.UTXO_BALANCE_INSUFFICIENT); | ||
let res; | ||
if (params.outputs.find(o => o.setMax) || | ||
params.certificates.length > 0 || | ||
params.withdrawals.length > 0 || | ||
if (outputs.find(o => o.setMax) || | ||
certificates.length > 0 || | ||
withdrawals.length > 0 || | ||
(options === null || options === void 0 ? void 0 : options.forceLargestFirstSelection)) { | ||
logger.debug('Running largest-first alg'); | ||
res = (0, largestFirst_1.largestFirst)(params, options); | ||
res = (0, largestFirst_1.largestFirst)(utxos, outputs, changeAddress, certificates, withdrawals, accountPubKey, options); | ||
} | ||
@@ -52,3 +57,3 @@ else { | ||
try { | ||
res = (0, randomImprove_1.randomImprove)(params, options); | ||
res = (0, randomImprove_1.randomImprove)(utxos, outputs, changeAddress, options); | ||
} | ||
@@ -59,3 +64,3 @@ catch (error) { | ||
logger.debug(`random-improve failed with ${error.code}. Retrying with largest-first alg.`); | ||
res = (0, largestFirst_1.largestFirst)(params, options); | ||
res = (0, largestFirst_1.largestFirst)(utxos, outputs, changeAddress, certificates, withdrawals, accountPubKey, options); | ||
} | ||
@@ -62,0 +67,0 @@ else { |
@@ -1,2 +0,2 @@ | ||
import { CoinSelectionParams, CoinSelectionResult, Options } from '../types/types'; | ||
export declare const largestFirst: (params: CoinSelectionParams, options?: Options | undefined) => CoinSelectionResult; | ||
import { Certificate, CoinSelectionResult, Options, UserOutput, Utxo, Withdrawal } from '../types/types'; | ||
export declare const largestFirst: (utxos: Utxo[], outputs: UserOutput[], changeAddress: string, certificates: Certificate[], withdrawals: Withdrawal[], accountPubKey: string, options?: Options | undefined) => CoinSelectionResult; |
@@ -27,9 +27,5 @@ "use strict"; | ||
const errors_1 = require("../utils/errors"); | ||
const largestFirst = (params, options) => { | ||
const largestFirst = (utxos, outputs, changeAddress, certificates, withdrawals, accountPubKey, options) => { | ||
var _a; | ||
const { utxos, outputs, changeAddress, certificates, withdrawals, accountPubKey, ttl, } = params; | ||
const txBuilder = (0, common_1.getTxBuilder)((_a = options === null || options === void 0 ? void 0 : options.feeParams) === null || _a === void 0 ? void 0 : _a.a); | ||
if (ttl) { | ||
txBuilder.set_ttl(ttl); | ||
} | ||
const usedUtxos = []; | ||
@@ -184,3 +180,2 @@ let sortedUtxos = (0, common_1.sortUtxos)(utxos); | ||
return { | ||
tx: { body: txBodyHex, hash: txHash, size: txBuilder.full_size() }, | ||
inputs: usedUtxos, | ||
@@ -192,3 +187,3 @@ outputs: finalOutputs, | ||
withdrawal: totalWithdrawal.to_str(), | ||
ttl, | ||
tx: { body: txBodyHex, hash: txHash, size: txBuilder.full_size() }, | ||
max, | ||
@@ -195,0 +190,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
import { CoinSelectionParams, CoinSelectionResult, Options } from '../types/types'; | ||
export declare const randomImprove: (params: Pick<CoinSelectionParams, 'utxos' | 'outputs' | 'changeAddress' | 'ttl'>, options?: Options | undefined) => CoinSelectionResult; | ||
import { CoinSelectionResult, Options, UserOutput, Utxo } from '../types/types'; | ||
export declare const randomImprove: (utxos: Utxo[], outputs: UserOutput[], changeAddress: string, options?: Options | undefined) => CoinSelectionResult; |
@@ -135,5 +135,4 @@ "use strict"; | ||
}; | ||
const randomImprove = (params, options) => { | ||
const randomImprove = (utxos, outputs, changeAddress, options) => { | ||
var _a; | ||
const { utxos, outputs, changeAddress, ttl } = params; | ||
const logger = (0, logger_1.getLogger)(!!(options === null || options === void 0 ? void 0 : options.debug)); | ||
@@ -145,5 +144,2 @@ if (outputs.length > utxos.length) { | ||
const txBuilder = (0, common_1.getTxBuilder)((_a = options === null || options === void 0 ? void 0 : options.feeParams) === null || _a === void 0 ? void 0 : _a.a); | ||
if (ttl) { | ||
txBuilder.set_ttl(ttl); | ||
} | ||
const { utxoSelected, utxoRemaining, preparedOutputs } = selection(utxos, outputs, txBuilder, changeAddress); | ||
@@ -173,3 +169,2 @@ // compute change and adjust for fee | ||
return { | ||
tx: { body: txBodyHex, hash: txHash, size: txBuilder.full_size() }, | ||
inputs: utxoSelected, | ||
@@ -181,5 +176,5 @@ outputs: finalOutputs, | ||
withdrawal: '0', | ||
ttl, | ||
tx: { body: txBodyHex, hash: txHash, size: txBuilder.full_size() }, | ||
}; | ||
}; | ||
exports.randomImprove = randomImprove; |
@@ -72,3 +72,2 @@ import * as CardanoWasm from '@emurgo/cardano-serialization-lib-browser'; | ||
withdrawal: string; | ||
ttl?: number; | ||
max?: string; | ||
@@ -109,10 +108,1 @@ } | ||
} | ||
export interface CoinSelectionParams { | ||
utxos: Utxo[]; | ||
outputs: UserOutput[]; | ||
changeAddress: string; | ||
certificates: Certificate[]; | ||
withdrawals: Withdrawal[]; | ||
accountPubKey: string; | ||
ttl?: number; | ||
} |
@@ -1,5 +0,5 @@ | ||
import { CoinSelectionParams, Options, PrecomposedTransaction } from './types/types'; | ||
export declare const coinSelection: (params: CoinSelectionParams, options?: Options | undefined) => PrecomposedTransaction; | ||
import { Certificate, Options, PrecomposedTransaction, UserOutput, Utxo, Withdrawal } from './types/types'; | ||
export declare const coinSelection: (utxos: Utxo[], outputs: UserOutput[], changeAddress: string, certificates: Certificate[], withdrawals: Withdrawal[], accountPubKey: string, options?: Options | undefined) => PrecomposedTransaction; | ||
export * as trezorUtils from './utils/trezor'; | ||
export * as types from './types/types'; | ||
export { CoinSelectionError } from './utils/errors'; |
@@ -6,9 +6,14 @@ import { ERROR } from './constants'; | ||
import { getLogger } from './utils/logger'; | ||
export const coinSelection = (params, options) => { | ||
export const coinSelection = (utxos, outputs, changeAddress, certificates, withdrawals, accountPubKey, options) => { | ||
const logger = getLogger(!!(options === null || options === void 0 ? void 0 : options.debug)); | ||
logger.debug('Args:', { | ||
params, | ||
utxos, | ||
outputs, | ||
changeAddress, | ||
certificates, | ||
withdrawals, | ||
accountPubKey, | ||
options, | ||
}); | ||
if (params.utxos.length === 0) { | ||
if (utxos.length === 0) { | ||
logger.debug('Empty Utxo set'); | ||
@@ -19,8 +24,8 @@ throw new CoinSelectionError(ERROR.UTXO_BALANCE_INSUFFICIENT); | ||
let res; | ||
if (params.outputs.find(o => o.setMax) || | ||
params.certificates.length > 0 || | ||
params.withdrawals.length > 0 || | ||
if (outputs.find(o => o.setMax) || | ||
certificates.length > 0 || | ||
withdrawals.length > 0 || | ||
(options === null || options === void 0 ? void 0 : options.forceLargestFirstSelection)) { | ||
logger.debug('Running largest-first alg'); | ||
res = largestFirst(params, options); | ||
res = largestFirst(utxos, outputs, changeAddress, certificates, withdrawals, accountPubKey, options); | ||
} | ||
@@ -30,3 +35,3 @@ else { | ||
try { | ||
res = randomImprove(params, options); | ||
res = randomImprove(utxos, outputs, changeAddress, options); | ||
} | ||
@@ -37,3 +42,3 @@ catch (error) { | ||
logger.debug(`random-improve failed with ${error.code}. Retrying with largest-first alg.`); | ||
res = largestFirst(params, options); | ||
res = largestFirst(utxos, outputs, changeAddress, certificates, withdrawals, accountPubKey, options); | ||
} | ||
@@ -40,0 +45,0 @@ else { |
@@ -1,2 +0,2 @@ | ||
import { CoinSelectionParams, CoinSelectionResult, Options } from '../types/types'; | ||
export declare const largestFirst: (params: CoinSelectionParams, options?: Options | undefined) => CoinSelectionResult; | ||
import { Certificate, CoinSelectionResult, Options, UserOutput, Utxo, Withdrawal } from '../types/types'; | ||
export declare const largestFirst: (utxos: Utxo[], outputs: UserOutput[], changeAddress: string, certificates: Certificate[], withdrawals: Withdrawal[], accountPubKey: string, options?: Options | undefined) => CoinSelectionResult; |
@@ -5,9 +5,5 @@ import { ERROR } from '../constants'; | ||
import { CoinSelectionError } from '../utils/errors'; | ||
export const largestFirst = (params, options) => { | ||
export const largestFirst = (utxos, outputs, changeAddress, certificates, withdrawals, accountPubKey, options) => { | ||
var _a; | ||
const { utxos, outputs, changeAddress, certificates, withdrawals, accountPubKey, ttl, } = params; | ||
const txBuilder = getTxBuilder((_a = options === null || options === void 0 ? void 0 : options.feeParams) === null || _a === void 0 ? void 0 : _a.a); | ||
if (ttl) { | ||
txBuilder.set_ttl(ttl); | ||
} | ||
const usedUtxos = []; | ||
@@ -162,3 +158,2 @@ let sortedUtxos = sortUtxos(utxos); | ||
return { | ||
tx: { body: txBodyHex, hash: txHash, size: txBuilder.full_size() }, | ||
inputs: usedUtxos, | ||
@@ -170,5 +165,5 @@ outputs: finalOutputs, | ||
withdrawal: totalWithdrawal.to_str(), | ||
ttl, | ||
tx: { body: txBodyHex, hash: txHash, size: txBuilder.full_size() }, | ||
max, | ||
}; | ||
}; |
@@ -1,2 +0,2 @@ | ||
import { CoinSelectionParams, CoinSelectionResult, Options } from '../types/types'; | ||
export declare const randomImprove: (params: Pick<CoinSelectionParams, 'utxos' | 'outputs' | 'changeAddress' | 'ttl'>, options?: Options | undefined) => CoinSelectionResult; | ||
import { CoinSelectionResult, Options, UserOutput, Utxo } from '../types/types'; | ||
export declare const randomImprove: (utxos: Utxo[], outputs: UserOutput[], changeAddress: string, options?: Options | undefined) => CoinSelectionResult; |
@@ -113,5 +113,4 @@ import { ERROR } from '../constants'; | ||
}; | ||
export const randomImprove = (params, options) => { | ||
export const randomImprove = (utxos, outputs, changeAddress, options) => { | ||
var _a; | ||
const { utxos, outputs, changeAddress, ttl } = params; | ||
const logger = getLogger(!!(options === null || options === void 0 ? void 0 : options.debug)); | ||
@@ -123,5 +122,2 @@ if (outputs.length > utxos.length) { | ||
const txBuilder = getTxBuilder((_a = options === null || options === void 0 ? void 0 : options.feeParams) === null || _a === void 0 ? void 0 : _a.a); | ||
if (ttl) { | ||
txBuilder.set_ttl(ttl); | ||
} | ||
const { utxoSelected, utxoRemaining, preparedOutputs } = selection(utxos, outputs, txBuilder, changeAddress); | ||
@@ -151,3 +147,2 @@ // compute change and adjust for fee | ||
return { | ||
tx: { body: txBodyHex, hash: txHash, size: txBuilder.full_size() }, | ||
inputs: utxoSelected, | ||
@@ -159,4 +154,4 @@ outputs: finalOutputs, | ||
withdrawal: '0', | ||
ttl, | ||
tx: { body: txBodyHex, hash: txHash, size: txBuilder.full_size() }, | ||
}; | ||
}; |
@@ -72,3 +72,2 @@ import * as CardanoWasm from '@emurgo/cardano-serialization-lib-browser'; | ||
withdrawal: string; | ||
ttl?: number; | ||
max?: string; | ||
@@ -109,10 +108,1 @@ } | ||
} | ||
export interface CoinSelectionParams { | ||
utxos: Utxo[]; | ||
outputs: UserOutput[]; | ||
changeAddress: string; | ||
certificates: Certificate[]; | ||
withdrawals: Withdrawal[]; | ||
accountPubKey: string; | ||
ttl?: number; | ||
} |
{ | ||
"name": "@fivebinaries/coin-selection", | ||
"version": "2.0.0-beta.8", | ||
"version": "2.0.0-beta.9", | ||
"description": "", | ||
@@ -27,3 +27,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"@emurgo/cardano-serialization-lib-nodejs": "10.0.0-beta.8", | ||
"@emurgo/cardano-serialization-lib-nodejs": "10.0.3", | ||
"@swc-node/jest": "^1.4.3", | ||
@@ -30,0 +30,0 @@ "@types/jest": "^27.4.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
137289
2802