Skip to content

Commit

Permalink
testing treasury balance reset
Browse files Browse the repository at this point in the history
  • Loading branch information
argonmining committed Aug 11, 2024
1 parent 4017738 commit c4ebb1f
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions src/trxs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,42 +40,55 @@ export default class trxManager {

// Aggregate balances by wallet address
for (const { address, balance } of balances) {
if (balance > 0) {
payments[address] = (payments[address] || 0n) + balance;
}
if (balance > 0) {
payments[address] = (payments[address] || 0n) + balance;
}
}

const paymentOutputs: IPaymentOutput[] = Object.entries(payments).map(([address, amount]) => ({
address: address as string, // Cast to string explicitly
amount,
address: address as string, // Cast to string explicitly
amount,
}));

if (paymentOutputs.length === 0) {
return this.monitoring.log('TrxManager: No payments found for current transfer cycle.');
return this.monitoring.log('TrxManager: No payments found for current transfer cycle.');
}

// Create and map transactions to addresses
const { transactions } = await createTransactions({
entries: this.context,
outputs: paymentOutputs,
changeAddress: this.address,
priorityFee: 0n
entries: this.context,
outputs: paymentOutputs,
changeAddress: this.address,
priorityFee: 0n
});

// Log the lengths to debug any potential mismatch
this.monitoring.debug(`Created ${transactions.length} transactions for ${paymentOutputs.length} outputs.`);

transactions.forEach((transaction, index) => {
const outputAddress = paymentOutputs[index].address;
const address = typeof outputAddress === 'string'
? outputAddress
: (outputAddress as Address).toString();
if (index >= paymentOutputs.length) {
this.monitoring.error(`TrxManager: Index ${index} out of bounds for paymentOutputs length ${paymentOutputs.length}`);
return;
}

const outputAddress = paymentOutputs[index]?.address;
if (!outputAddress) {
this.monitoring.error(`TrxManager: No address found for transaction at index ${index}`);
return;
}

const address = typeof outputAddress === 'string'
? outputAddress
: (outputAddress as Address).toString();

this.transactionAddressMap.set(transaction.id, address);
this.transactionAddressMap.set(transaction.id, address);
});

// Process each transaction sequentially
for (const transaction of transactions) {
await this.processTransaction(transaction);
await this.processTransaction(transaction);
}
}
}

private async processTransaction(transaction: PendingTransaction) {
if (DEBUG) this.monitoring.debug(`TrxManager: Signing transaction ID: ${transaction.id}`);
Expand Down

0 comments on commit c4ebb1f

Please sign in to comment.