import type { Network } from '../networks' ; import type { TxType } from '../coinselect/utils' ; export type ComposeInput = { index : number ; transactionHash : string ; value : string ; addressPath : [ number , number ] ; height ? : number ; coinbase : boolean ; tsize : number ; vsize : number ; own : boolean ; required ? : boolean ; confirmations ? : number ; } ; export type ComposeFinalOutput = { type : 'complete' ; address : string ; amount : string ; } | { type : 'send-max' ; address : string ; } | { type : 'opreturn' ; dataHex : string ; } ; export type ComposeNotFinalOutput = { type : 'send-max-noaddress' ; } | { type : 'noaddress' ; amount : string ; } ; export type ComposeOutput = ComposeFinalOutput | ComposeNotFinalOutput ; export type ComposeRequest = { txType ? : TxType ; utxos : ComposeInput [ ] ; outputs : ComposeOutput [ ] ; height : number ; feeRate : string ; basePath : number [ ] ; network : Network ; changeId : number ; changeAddress : string ; dustThreshold : number ; baseFee ? : number ; floorBaseFee ? : boolean ; dustOutputFee ? : number ; skipUtxoSelection ? : boolean ; skipPermutation ? : boolean ; } ; export function splitByCompleteness ( outputs ) { const complete = [ ] ; const incomplete = [ ] ; outputs . forEach ( output => { if ( output . type === 'complete' || output . type === 'send-max' || output . type === 'opreturn' ) { complete . push ( output ) ; } else { incomplete . push ( output ) ; } } ) ; return { complete , incomplete , } ; } export function getMax ( outputs ) { const countMaxRequests = outputs . filter ( output => output . type === 'send-max-noaddress' || output . type === 'send-max' ) ; if ( countMaxRequests . length >= 2 ) { throw new Error ( 'TWO-SEND-MAX' ) ; } const id = outputs . findIndex ( output => output . type === 'send-max-noaddress' || output . type === 'send-max' ) ; const exists = countMaxRequests . length === 1 ; return { id , exists , } ; }