/* Ċ Ġ* ĠCopyright Ġ 2 0 1 9 ĠAl gor and , ĠInc . Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense Ċ Ġ*/ Ċ Ċ package Ġcom . al gor and . android . mapper Ċ Ċ import Ġcom . al gor and . android . models . Base Asset Transfer Transaction Ċ import Ġcom . al gor and . android . models . Base Wallet Connect Transaction Ċ import Ġcom . al gor and . android . models . WC Algo Transaction Request Ċ import Ġcom . al gor and . android . models . Wallet Connect Peer Meta Ċ import Ġcom . al gor and . android . models . Wallet Connect Signer Ċ import Ġcom . al gor and . android . models . Wallet Connect Transaction Request Ċ import Ġcom . al gor and . android . utils . Account CacheManager Ċ import Ġcom . al gor and . android . utils . wallet connect . Wallet Connect Transaction Error Provider Ċ import Ġjava . math . BigInteger . ZERO Ċ import Ġjavax . inject . Inject Ċ Ċ @ SuppressWarnings (" Return Count ") Ċ class ĠAsset Transfer Transaction Mapper Ġ@ Inject Ġconstructor ( ĊĠĠĠ Ġprivate Ġval Ġaccount CacheManager : ĠAccount CacheManager , ĊĠĠĠ Ġprivate Ġval Ġerror Provider : ĠWallet Connect Transaction Error Provider Ċ ) Ġ: ĠBase Wallet Connect Transaction Mapper () Ġ{ ĊĊĠĠĠ Ġoverride Ġfun Ġcreate Transaction ( ĊĠĠĠĠĠĠĠ Ġpeer Meta : ĠWallet Connect Peer Meta , ĊĠĠĠĠĠĠĠ Ġtransaction Request : ĠWallet Connect Transaction Request , ĊĠĠĠĠĠĠĠ Ġraw Txn : ĠWC Algo Transaction Request ĊĠĠĠ Ġ): ĠBase Wallet Connect Transaction ? Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġwith ( transaction Request ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwhen Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ! re key Address . isNull Or Blank () Ġ&& Ġ! asset Close To Address . isNull Or Blank () Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcreate Asset Transfer Transaction With Re key And Close ( peer Meta , Ġtransaction Request , Ġraw Txn ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġasset Close To Address Ġ!= Ġnull Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcreate Asset Transfer Transaction With Close ( peer Meta , Ġtransaction Request , Ġraw Txn ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ( asset Amount Ġ== Ġnull Ġ|| Ġasset Amount Ġ== ĠZERO ) Ġ&& Ġsender Address Ġ== Ġasset Receiver Address Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcreate Asset Opt In Transaction ( peer Meta , Ġtransaction Request , Ġraw Txn ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġre key Address Ġ!= Ġnull Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcreate Asset Transfer Transaction With Re key ( peer Meta , Ġtransaction Request , Ġraw Txn ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġelse Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcreate Asset Transfer Transaction ( peer Meta , Ġtransaction Request , Ġraw Txn ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcreate Asset Transfer Transaction With Close ( ĊĠĠĠĠĠĠĠ Ġpeer Meta : ĠWallet Connect Peer Meta , ĊĠĠĠĠĠĠĠ Ġtransaction Request : ĠWallet Connect Transaction Request , ĊĠĠĠĠĠĠĠ Ġraw Transaction : ĠWC Algo Transaction Request ĊĠĠĠ Ġ): ĠBase Asset Transfer Transaction . Asset Transfer Transaction With Close ? Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġwith ( transaction Request ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġsender Wallet Connect Address Ġ= Ġcreate Wallet Connect Address ( sender Address ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠBase Asset Transfer Transaction . Asset Transfer Transaction With Close ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġraw Transaction Payload Ġ= Ġraw Transaction , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġwallet Connect Transaction Params Ġ= Ġcreate Transaction Params ( transaction Request ) Ġ?: Ġreturn Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġnote Ġ= Ġdecoded Note , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġasset Receiver Address Ġ= Ġcreate Wallet Connect Address ( asset Receiver Address ) Ġ?: Ġreturn Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsender Address Ġ= Ġsender Wallet Connect Address Ġ?: Ġreturn Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġasset Id Ġ= Ġasset Id Ġ?: Ġreturn Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġpeer Meta Ġ= Ġpeer Meta , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġasset Close To Address Ġ= Ġcreate Wallet Connect Address ( asset Close To Address ) Ġ?: Ġreturn Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsigner Ġ= ĠWallet Connect Signer . create ( raw Transaction , Ġsender Wallet Connect Address , Ġerror Provider ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġasset Amount Ġ= Ġasset Amount Ġ?: ĠZERO , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġaccount Cache Data Ġ= Ġaccount CacheManager . getCache Data ( sender Wallet Connect Address . decoded Address ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcreate Asset Transfer Transaction With Re key ( ĊĠĠĠĠĠĠĠ Ġpeer Meta : ĠWallet Connect Peer Meta , ĊĠĠĠĠĠĠĠ Ġtransaction Request : ĠWallet Connect Transaction Request , ĊĠĠĠĠĠĠĠ Ġraw Transaction : ĠWC Algo Transaction Request ĊĠĠĠ Ġ): ĠBase Asset Transfer Transaction . Asset Transfer Transaction With Re key ? Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġwith ( transaction Request ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġsender Wallet Connect Address Ġ= Ġcreate Wallet Connect Address ( sender Address ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠBase Asset Transfer Transaction . Asset Transfer Transaction With Re key ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġraw Transaction Payload Ġ= Ġraw Transaction , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġwallet Connect Transaction Params Ġ= Ġcreate Transaction Params ( transaction Request ) Ġ?: Ġreturn Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġnote Ġ= Ġdecoded Note , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġasset Receiver Address Ġ= Ġcreate Wallet Connect Address ( asset Receiver Address ) Ġ?: Ġreturn Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsender Address Ġ= Ġsender Wallet Connect Address Ġ?: Ġreturn Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġasset Id Ġ= Ġasset Id Ġ?: Ġreturn Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġpeer Meta Ġ= Ġpeer Meta , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġre key Address Ġ= Ġcreate Wallet Connect Address ( re key Address ) Ġ?: Ġreturn Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsigner Ġ= ĠWallet Connect Signer . create ( raw Transaction , Ġsender Wallet Connect Address , Ġerror Provider ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġasset Amount Ġ= Ġasset Amount Ġ?: ĠZERO , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġaccount Cache Data Ġ= Ġaccount CacheManager . getCache Data ( sender Wallet Connect Address . decoded Address ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcreate Asset Transfer Transaction With Re key And Close ( ĊĠĠĠĠĠĠĠ Ġpeer Meta : ĠWallet Connect Peer Meta , ĊĠĠĠĠĠĠĠ Ġtransaction Request : ĠWallet Connect Transaction Request , ĊĠĠĠĠĠĠĠ Ġraw Transaction : ĠWC Algo Transaction Request ĊĠĠĠ Ġ): ĠBase Asset Transfer Transaction . Asset Transfer Transaction With Re key And Close ? Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġwith ( transaction Request ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġsender Wallet Connect Address Ġ= Ġcreate Wallet Connect Address ( sender Address ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠBase Asset Transfer Transaction . Asset Transfer Transaction With Re key And Close ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġraw Transaction Payload Ġ= Ġraw Transaction , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġwallet Connect Transaction Params Ġ= Ġcreate Transaction Params ( transaction Request ) Ġ?: Ġreturn Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġnote Ġ= Ġdecoded Note , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġasset Receiver Address Ġ= Ġcreate Wallet Connect Address ( asset Receiver Address ) Ġ?: Ġreturn Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsender Address Ġ= Ġsender Wallet Connect Address Ġ?: Ġreturn Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġasset Id Ġ= Ġasset Id Ġ?: Ġreturn Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġpeer Meta Ġ= Ġpeer Meta , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġre key Address Ġ= Ġcreate Wallet Connect Address ( re key Address ) Ġ?: Ġreturn Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsigner Ġ= ĠWallet Connect Signer . create ( raw Transaction , Ġsender Wallet Connect Address , Ġerror Provider ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġasset Amount Ġ= Ġasset Amount Ġ?: ĠZERO , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġaccount Cache Data Ġ= Ġaccount CacheManager . getCache Data ( sender Wallet Connect Address . decoded Address ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġclose Address Ġ= Ġcreate Wallet Connect Address ( asset Close To Address ) Ġ?: Ġreturn Ġnull ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcreate Asset Transfer Transaction ( ĊĠĠĠĠĠĠĠ Ġpeer Meta : ĠWallet Connect Peer Meta , ĊĠĠĠĠĠĠĠ Ġtransaction Request : ĠWallet Connect Transaction Request , ĊĠĠĠĠĠĠĠ Ġraw Transaction : ĠWC Algo Transaction Request ĊĠĠĠ Ġ): ĠBase Asset Transfer Transaction . Asset Transfer Transaction ? Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġwith ( transaction Request ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġsender Wallet Connect Address Ġ= Ġcreate Wallet Connect Address ( sender Address ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠBase Asset Transfer Transaction . Asset Transfer Transaction ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġraw Transaction Payload Ġ= Ġraw Transaction , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġwallet Connect Transaction Params Ġ= Ġcreate Transaction Params ( transaction Request ) Ġ?: Ġreturn Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġnote Ġ= Ġdecoded Note , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġasset Receiver Address Ġ= Ġcreate Wallet Connect Address ( asset Receiver Address ) Ġ?: Ġreturn Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsender Address Ġ= Ġsender Wallet Connect Address Ġ?: Ġreturn Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġasset Id Ġ= Ġasset Id Ġ?: Ġreturn Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġpeer Meta Ġ= Ġpeer Meta , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġasset Amount Ġ= Ġasset Amount Ġ?: ĠZERO , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsigner Ġ= ĠWallet Connect Signer . create ( raw Transaction , Ġsender Wallet Connect Address , Ġerror Provider ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġaccount Cache Data Ġ= Ġaccount CacheManager . getCache Data ( sender Wallet Connect Address . decoded Address ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcreate Asset Opt In Transaction ( ĊĠĠĠĠĠĠĠ Ġpeer Meta : ĠWallet Connect Peer Meta , ĊĠĠĠĠĠĠĠ Ġtransaction Request : ĠWallet Connect Transaction Request , ĊĠĠĠĠĠĠĠ Ġraw Transaction : ĠWC Algo Transaction Request ĊĠĠĠ Ġ): ĠBase Asset Transfer Transaction . Asset Opt In Transaction ? Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġwith ( transaction Request ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġsender Wallet Connect Address Ġ= Ġcreate Wallet Connect Address ( sender Address ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠBase Asset Transfer Transaction . Asset Opt In Transaction ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġraw Transaction Payload Ġ= Ġraw Transaction , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġwallet Connect Transaction Params Ġ= Ġcreate Transaction Params ( transaction Request ) Ġ?: Ġreturn Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġnote Ġ= Ġdecoded Note , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġasset Receiver Address Ġ= Ġcreate Wallet Connect Address ( asset Receiver Address ) Ġ?: Ġreturn Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsender Address Ġ= Ġsender Wallet Connect Address Ġ?: Ġreturn Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġasset Id Ġ= Ġasset Id Ġ?: Ġreturn Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġpeer Meta Ġ= Ġpeer Meta , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsigner Ġ= ĠWallet Connect Signer . create ( raw Transaction , Ġsender Wallet Connect Address , Ġerror Provider ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġaccount Cache Data Ġ= Ġaccount CacheManager . getCache Data ( sender Wallet Connect Address . decoded Address ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ