Skip to content

Commit

Permalink
fixup! Break out piratechain into its own implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
peachbits committed Sep 12, 2023
1 parent 73b72c7 commit 5bf4685
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/piratechain/PiratechainEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ export class PiratechainEngine extends CurrencyEngine<
blockHeight: tx.minedHeight,
nativeAmount: netNativeAmount,
isSend: netNativeAmount.startsWith('-'),
memos: [],
networkFee: this.networkInfo.defaultNetworkFee,
ourReceiveAddresses, // blank if you sent money otherwise array of addresses that are yours in this transaction
signedTx: '',
Expand Down Expand Up @@ -303,6 +304,7 @@ export class PiratechainEngine extends CurrencyEngine<
async makeSpend(edgeSpendInfoIn: EdgeSpendInfo): Promise<EdgeTransaction> {
if (!this.isSynced()) throw new Error('Cannot spend until wallet is synced')
const { edgeSpendInfo, currencyCode } = this.makeSpendCheck(edgeSpendInfoIn)
const { memos = [] } = edgeSpendInfo
const spendTarget = edgeSpendInfo.spendTargets[0]
const { publicAddress, nativeAmount } = spendTarget

Expand Down Expand Up @@ -346,6 +348,7 @@ export class PiratechainEngine extends CurrencyEngine<
blockHeight: 0, // blockHeight
nativeAmount: `-${totalTxAmount}`, // nativeAmount
isSend: nativeAmount.startsWith('-'),
memos,
networkFee: this.networkInfo.defaultNetworkFee, // networkFee
ourReceiveAddresses: [], // ourReceiveAddresses
signedTx: '', // signedTx
Expand All @@ -365,6 +368,7 @@ export class PiratechainEngine extends CurrencyEngine<
edgeTransaction: EdgeTransaction,
opts?: EdgeEnginePrivateKeyOptions
): Promise<EdgeTransaction> {
const { memos } = edgeTransaction
const piratechainPrivateKeys = asPiratechainPrivateKeys(this.pluginId)(
opts?.privateKeys
)
Expand All @@ -374,14 +378,15 @@ export class PiratechainEngine extends CurrencyEngine<
)
throw new Error('Invalid spend targets')

const memo = memos[0]?.type === 'text' ? memos[0].value : ''
const spendTarget = edgeTransaction.spendTargets[0]
const txParams: PiratechainSpendInfo = {
zatoshi: sub(
abs(edgeTransaction.nativeAmount),
edgeTransaction.networkFee
),
toAddress: spendTarget.publicAddress,
memo: spendTarget.memo ?? spendTarget.uniqueIdentifier ?? '',
memo,
fromAccountIndex: 0,
spendingKey: piratechainPrivateKeys.spendKey
}
Expand Down

0 comments on commit 5bf4685

Please sign in to comment.