citadel-tech / coinswap

Functioning, minimal-viable binaries and libraries to perform a trustless, p2p Maxwell-Belcher Coinswap Protocol
https://gist.github.com/chris-belcher/9144bd57a91c194e332fb5ca371d0964
Other
69 stars 44 forks source link

Refactor transaction creating apis #267

Open KnowWhoami opened 2 hours ago

KnowWhoami commented 2 hours ago

Currently we have different types of apis which focuses on creating a particular types of transactions. for eg

But all these api's do same work at some level -> i.e they all contain reductant code for creating a transaction , selecting required utxos etc. This redundancy can be minimised by following proposed structural design:


fn create_signed_tx(fee:Amount, amount:SendAmount, destinations:Destination, coins_to_spend)-> Result<Transaction, WalletError>{
   // private function
   // A general tx generating api which will create any type of transactions , sign it and return tx instance.

   // implementation -> same as `spend_from_wallet` api.

   return transaction
}

pub create_fedility{

   // do some work  related to fedility.

   // select required utxos for making fidelity bonds.
   let selected_utxos= self.coin_select(..);

   // create tx instance and sign it.  
   let signed_tx= create_signed_tx(...);

   // do some work related to fidelity.   
}

// .... Similarly we can create other specific transaction api which will be wrappers .

Enhancements:

KnowWhoami commented 2 hours ago

I am taking this up.