Skip to content

Instantly share code, notes, and snippets.

@saltyskip
Created November 25, 2020 08:07
Show Gist options
  • Save saltyskip/149fd05c2531c7b8bf347e9ea88109b6 to your computer and use it in GitHub Desktop.
Save saltyskip/149fd05c2531c7b8bf347e9ea88109b6 to your computer and use it in GitHub Desktop.
class BcomBlockchainTransactionBuilder {
private var tx: BcomBlockchainTransaction
init(signingWallet: BcomWallet, chainAssetProtocol: ChainAssetProtocol, amount: Decimal, assetId: String) {
tx = BcomBlockchainTransaction(signingWallet: signingWallet, chainAssetProtocol: chainAssetProtocol, amount: amount, assetId: assetId)
}
//Chain Level Builder
func buildBitcoinCash(utxos: [UTXO], satsPerByteFee: Int) -> BitcoinCashBuilder {
tx.satsPerByteFee = satsPerByteFee
tx.utxos = utxos
return BitcoinCashBuilder(tx: tx)
}
class BitcoinCashBuilder {
private var tx: BcomBlockchainTransaction
init(tx: BcomBlockchainTransaction) { self.tx = tx }
func buildSLP(slpUtxos: [SLPUTXO]) -> SLPBuilder {
return SLPBuilder(tx: tx, slpUtxos: slpUtxos)
}
//finish here
func build() -> BcomBlockchainTransaction {
return tx
}
}
class SLPBuilder {
private var tx: BcomBlockchainTransaction
init(tx: BcomBlockchainTransaction, slpUtxos: [SLPUTXO]) { self.tx = tx }
func build() -> BcomBlockchainTransaction{
return tx
}
}
public class BlockchainTransactionGenerator {
public func createTransaction(_ tx: BcomBlockchainTransaction) -> Data {
switch tx.chainAssetProtocol {
case .bch, .btc:
return createBitcoinTransaction(wallet: tx.wallet,
chainAssetProtocol: tx.chainAssetProtocol,
amount: tx.amount,
useMaxAmount: false,
destination: "",
allAvailableUTXOs: tx.utxos!)
case .slp:
return createSLPTransaction()
case .eth:
return createEthereumTransaction()
case .erc20:
return createEthereumContractTransaction()
}
}
}
BcomBlockchainTransactionBuilder(signingWallet: wallet, chainAssetProtocol: .bch, amount: Decimal.zero, assetId: "bch")
.buildBitcoinCash(utxos: [], satsPerByteFee: 1)
.buildSLP(slpUtxos: [])
.build()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment