package Ġcom . l umi wallet . android . core . bitcoin Vault . transaction Ċ Ċ import Ġcom . l umi wallet . android . core . bitcoin Vault . core . Seg wit Address Ċ import Ġcom . l umi wallet . android . core . bitcoin Vault . params . Bitcoin Vault Params Ċ import Ġcom . l umi wallet . android . core . bitcoin Vault . script . Script Type Ċ import Ġcom . l umi wallet . android . core . utils . Base 5 8 Ċ import Ġcom . l umi wallet . android . core . utils . btc _ based . ByteBuffer Ċ import Ġcom . l umi wallet . android . core . utils . btc _ based . Error Messages Ċ import Ġcom . l umi wallet . android . core . utils . btc _ based . Validation Utils . is Base 5 8 Ċ import Ġcom . l umi wallet . android . core . utils . btc _ based . Validation Utils . isEmpty Ċ import Ġcom . l umi wallet . android . core . utils . btc _ based . types . UL ong Ċ import Ġcom . l umi wallet . android . core . utils . btc _ based . types . Var Int Ċ import Ġcom . l umi wallet . android . core . utils . hex Ċ Ċ enum Ġclass ĠOutput Type ( val Ġdesc : ĠString ) Ġ{ ĊĠĠĠ ĠCUSTOM (" Custom "), ĊĠĠĠ ĠCHANGE (" Change ") Ċ } Ċ Ċ internal Ġclass ĠOutput ( ĊĠĠĠ Ġval Ġsat oshi : ĠLong , Ġ// Ġamount ĊĠĠĠ Ġprivate Ġval Ġdestination : ĠString , ĊĠĠĠ Ġprivate Ġval Ġtype : ĠOutput Type Ċ ) Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġdecoded Address : ĠByteArray ĊĠĠĠ Ġprivate Ġval Ġaddress Type : ĠScript Type ĊĊĠĠĠ Ġprivate Ġval Ġlocking Script : ĠByteArray ĊĠĠĠĠĠĠĠ Ġget () Ġ= ĠScript PubKey Producer . produce Script ( decoded Address , Ġaddress Type ) ĊĊĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠ Ġvalidate Output Data ( sat oshi , Ġdestination ) ĊĠĠĠĠĠĠĠ Ġthis . address Type Ġ= Ġdecode Address Type ( destination ) ĊĠĠĠĠĠĠĠ Ġthis . decoded Address Ġ= Ġdecode And Validate Address ( destination , Ġaddress Type ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġserialize For Sig Hash (): ĠByteArray Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġlocking Script Ġ= Ġlocking Script ĊĠĠĠĠĠĠĠ Ġreturn ĠByteBuffer (). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġappend (* UL ong . of ( sat oshi ). as Lit End Bytes ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġappend (* Var Int . of ( lock ing Script . size . to Long ()). as Lit End Bytes ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġappend (* lock ing Script ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. bytes ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġfill Transaction ( transaction : ĠTransaction ) Ġ{ ĊĠĠĠĠĠĠĠ Ġtransaction . add Header ( Transaction . Tx Part . OUTPUT ) ĊĠĠĠĠĠĠĠ Ġtransaction . addData ( Transaction . Tx Part . AMOUNT , ĠU Long . of ( sat oshi ). toString ()) ĊĠĠĠĠĠĠĠ Ġtransaction . addData ( Transaction . Tx Part . LOCK _ LENGTH , ĠVar Int . of ( lock ing Script . size . to Long ()). toString ()) ĊĠĠĠĠĠĠĠ Ġtransaction . addData ( Transaction . Tx Part . LOCK , Ġlocking Script . hex ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠtoString (): ĠString Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġ"$ destination Ġ$ sat oshi " ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġget Destination (): ĠString Ġ= Ġdestination ĊĊĠĠĠ Ġprivate Ġfun Ġvalidate Output Data ( sat oshi : ĠLong , Ġdestination : ĠString ) Ġ{ ĊĠĠĠĠĠĠĠ Ġvalidate Destination Address ( destination ) ĊĠĠĠĠĠĠĠ Ġvalidate Amount ( sat oshi ); ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġvalidate Amount ( sat oshi : ĠLong ) Ġ{ ĊĠĠĠĠĠĠĠ Ġrequire ( sat oshi Ġ> Ġ 0 ) Ġ{ ĠError Messages . OUTPUT _ AMOUNT _ NOT _ POSITIVE Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġvalidate Destination Address ( destination : ĠString ) Ġ{ ĊĠĠĠĠĠĠĠ Ġrequire (! isEmpty ( destination )) Ġ{ ĠError Messages . OUTPUT _ ADDRESS _ EMPTY Ġ} ĊĊĠĠĠĠĠĠĠ Ġrequire ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdestination . startsWith ( Bitcoin Vault Params . seg wit Address H rp !! ) Ġ|| ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠBase 5 8 . decode Checked ( destination )[ 0 ] Ġ== ĠBitcoin Vault Params . address Header . to Byte () Ġ|| ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠBase 5 8 . decode Checked ( destination )[ 0 ] Ġ== ĠBitcoin Vault Params . p 2 SH Header . to Byte () ĊĠĠĠĠĠĠĠ Ġ) Ġ{ ĠError Messages . OUTPUT _ ADDRESS _ WRONG _ PREFIX Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġdecode Address Type ( address : ĠString ): ĠScript Type Ġ= ĊĠĠĠĠĠĠĠ ĠScript Type . from Address Prefix ( address ) ĊĊĠĠĠ Ġprivate Ġfun Ġdecode And Validate Address ( address : ĠString , Ġaddress Type : ĠScript Type ): ĠByteArray Ġ= ĊĠĠĠĠĠĠĠ Ġwhen Ġ( address Type ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠScript Type . P 2 W PK H Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠSe gw it Address . from Be ch 3 2 ( Bitcoin Vault Params , Ġaddress ). w itness Program ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ ĠScript Type . P 2 PK H , ĠScript Type . P 2 SH Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġrequire ( is Base 5 8 ( destination )) Ġ{ ĠError Messages . OUTPUT _ ADDRESS _ NOT _ BASE _ 5 8 Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠBase 5 8 . decode Checked ( address ). drop ( 1 ). toByteArray () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġelse Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġthrow ĠIllegalArgumentException ( Error Messages . OUTPUT _ ADDRESS _ WRONG _ PREFIX ) ĊĠĠĠĠĠĠĠ Ġ} Ċ }