Skip to content

Commit

Permalink
Merge pull request #23 from DIG-Network/release/v0.0.1-alpha.23
Browse files Browse the repository at this point in the history
Release/v0.0.1 alpha.23
  • Loading branch information
MichaelTaylor3D authored Sep 17, 2024
2 parents 47334da + d3030dc commit 0da303e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 18 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.0.1-alpha.23](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.22...v0.0.1-alpha.23) (2024-09-17)


### Features

* add sendEqualBulkPayments and sendBulkPayments ([ca4a1e5](https://github.com/DIG-Network/dig-chia-sdk/commit/ca4a1e5dde47a4492bfb4b74390c93e12447348d))
* add sendEqualBulkPayments and sendBulkPayments ([1451d83](https://github.com/DIG-Network/dig-chia-sdk/commit/1451d83b23db4a42b83729e176236ec0f5a0da12))

### [0.0.1-alpha.22](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.21...v0.0.1-alpha.22) (2024-09-17)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dignetwork/dig-sdk",
"version": "0.0.1-alpha.22",
"version": "0.0.1-alpha.23",
"description": "",
"type": "commonjs",
"main": "./dist/index.js",
Expand Down
71 changes: 56 additions & 15 deletions src/DigNetwork/DigPeer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ export class DigPeer {
}

// Fetch the manifest.dat file content from the propagation server
const manifestContent = await this.propagationServer.getStoreData("manifest.dat");
const manifestContent = await this.propagationServer.getStoreData(
"manifest.dat"
);
const manifestHashes: string[] = manifestContent
.split("\n")
.filter(Boolean);
Expand Down Expand Up @@ -175,7 +177,9 @@ export class DigPeer {
}

// Fetch the manifest.dat file content from the content server
const manifestContent = await this.propagationServer.getStoreData("manifest.dat");
const manifestContent = await this.propagationServer.getStoreData(
"manifest.dat"
);
const manifestHashes: string[] = manifestContent
.split("\n")
.filter(Boolean);
Expand All @@ -188,24 +192,53 @@ export class DigPeer {
}
}

public async sendPayment(walletName: string, amount: bigint): Promise<void> {
const paymentAddress = await this.contentServer.getPaymentAddress();
console.log(`Sending ${amount} Mojos to ${paymentAddress}...`);
public static sendEqualBulkPayments(
walletName: string,
addresses: string[],
totalAmount: bigint
): Promise<void> {
// Use a Set to ensure unique addresses
const uniqueAddresses = Array.from(new Set(addresses));

// Convert unique addresses to puzzle hashes
const puzzleHashes = uniqueAddresses.map((address) =>
addressToPuzzleHash(address)
);

// Calculate amount per puzzle hash
const amountPerPuzzleHash = totalAmount / BigInt(puzzleHashes.length);

// Create outputs array
const outputs: { puzzleHash: Buffer; amount: bigint }[] = puzzleHashes.map(
(puzzleHash) => ({
puzzleHash,
amount: amountPerPuzzleHash,
})
);

// Call the sendBulkPayments function with the generated outputs
return DigPeer.sendBulkPayments(walletName, outputs);
}

public static async sendBulkPayments(
walletName: string,
outputs: { puzzleHash: Buffer; amount: bigint }[]
): Promise<void> {
const fee = BigInt(1000);
const wallet = await Wallet.load(walletName);
const publicSyntheticKey = await wallet.getPublicSyntheticKey();
const peer = await FullNodePeer.connect();
const coins = await selectUnspentCoins(peer, amount, fee, [], walletName);
const paymentAddressPuzzleHash = addressToPuzzleHash(paymentAddress);


const outputs = [
{
puzzleHash: paymentAddressPuzzleHash,
amount: amount,
},
];
const totalAmount = outputs.reduce(
(acc, output) => acc + output.amount,
BigInt(0)
);
const coins = await selectUnspentCoins(
peer,
totalAmount,
fee,
[],
walletName
);

const coinSpends = await sendXch(publicSyntheticKey, coins, outputs, fee);

Expand All @@ -223,4 +256,12 @@ export class DigPeer {

await FullNodePeer.waitForConfirmation(getCoinId(coins[0]));
}

public async sendPayment(walletName: string, amount: bigint): Promise<void> {
const paymentAddress = await this.contentServer.getPaymentAddress();
const paymentAddressPuzzleHash = addressToPuzzleHash(paymentAddress);
return DigPeer.sendBulkPayments(walletName, [
{ puzzleHash: paymentAddressPuzzleHash, amount },
]);
}
}

0 comments on commit 0da303e

Please sign in to comment.