solotto 1.1.4 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -3
- package/package.json +1 -1
- package/solotto.d.ts +7 -4
- package/solotto.js +12 -9
package/README.md
CHANGED
|
@@ -429,7 +429,7 @@ const state = await lottery.GetLottery(authority, lotteryId, fees);
|
|
|
429
429
|
isActive: true, // Whether the lottery is active
|
|
430
430
|
prizePoolBalance: 3780000000, // Prize pool in lamports (after fees if fees=true)
|
|
431
431
|
drawInitiated: false, // Whether a draw has been initiated
|
|
432
|
-
prizePoolAddress: "Pubkey...", //
|
|
432
|
+
prizePoolAddress: "Pubkey...", // Per-lottery prize pool PDA (seeds: ["prize-pool", lotteryPDA])
|
|
433
433
|
lotteryAddress: "Pubkey...", // Lottery PDA
|
|
434
434
|
release: "Pubkey...", // Release address (lottery PDA)
|
|
435
435
|
releaseTime: null, // Unix timestamp when unclaimed prizes can be released (null if not set)
|
|
@@ -494,7 +494,7 @@ const ticket = await lottery.GetTicket(authority, lotteryId, ticketNumber);
|
|
|
494
494
|
|
|
495
495
|
#### GetTickets
|
|
496
496
|
|
|
497
|
-
Fetches all tickets for a lottery, optionally filtered by buyer, grouped by owner, and/or enriched with purchase timestamps.
|
|
497
|
+
Fetches all tickets for a lottery, optionally filtered by buyer, grouped by owner, and/or enriched with purchase timestamps and transaction signatures.
|
|
498
498
|
|
|
499
499
|
```js
|
|
500
500
|
// Get all tickets
|
|
@@ -508,6 +508,9 @@ const grouped = await lottery.GetTickets(authority, lotteryId, false, true);
|
|
|
508
508
|
|
|
509
509
|
// Get all tickets with purchase timestamps
|
|
510
510
|
const withTime = await lottery.GetTickets(authority, lotteryId, false, false, true);
|
|
511
|
+
|
|
512
|
+
// Get all tickets with timestamps and signatures
|
|
513
|
+
const full = await lottery.GetTickets(authority, lotteryId, false, false, true, true);
|
|
511
514
|
```
|
|
512
515
|
|
|
513
516
|
| Parameter | Type | Default | Description |
|
|
@@ -516,7 +519,10 @@ const withTime = await lottery.GetTickets(authority, lotteryId, false, false, tr
|
|
|
516
519
|
| `lotteryId` | `Number` | — | The lottery ID. |
|
|
517
520
|
| `buyer` | `{publicKey} \| false` | `false` | Optional buyer to filter by. |
|
|
518
521
|
| `group` | `Boolean` | `false` | If `true`, groups tickets by owner. |
|
|
519
|
-
| `time` | `Boolean` | `false` | If `true`,
|
|
522
|
+
| `time` | `Boolean` | `false` | If `true`, includes the block timestamp for each ticket. |
|
|
523
|
+
| `signature` | `Boolean` | `false` | If `true`, includes the transaction signature for each ticket. |
|
|
524
|
+
|
|
525
|
+
> **Note:** The `time` and `signature` options share a single RPC call per ticket, so enabling both does not double the number of requests.
|
|
520
526
|
|
|
521
527
|
**Returns (ungrouped):**
|
|
522
528
|
|
|
@@ -534,6 +540,7 @@ const withTime = await lottery.GetTickets(authority, lotteryId, false, false, tr
|
|
|
534
540
|
ticketNumber: 42,
|
|
535
541
|
ticketPda: "Pubkey...",
|
|
536
542
|
time: null, // Unix timestamp when time=true, null otherwise
|
|
543
|
+
signature: "TxSig...", // Present only when signature=true
|
|
537
544
|
},
|
|
538
545
|
// ... sorted descending by ticket number
|
|
539
546
|
],
|
package/package.json
CHANGED
package/solotto.d.ts
CHANGED
|
@@ -107,6 +107,8 @@ declare module "solotto" {
|
|
|
107
107
|
ticketPda: string;
|
|
108
108
|
/** Unix block timestamp of ticket purchase, or `null` when `time=false`. */
|
|
109
109
|
time: number | null;
|
|
110
|
+
/** Transaction signature. Present only when `signature=true`. */
|
|
111
|
+
signature?: string;
|
|
110
112
|
}
|
|
111
113
|
|
|
112
114
|
interface GroupedTicketOwner {
|
|
@@ -323,13 +325,14 @@ declare module "solotto" {
|
|
|
323
325
|
ticket: number
|
|
324
326
|
): Promise<TicketInfo>;
|
|
325
327
|
|
|
326
|
-
/** Fetch all tickets for a lottery, optionally filtered by buyer, grouped by owner, and/or with timestamps. */
|
|
328
|
+
/** Fetch all tickets for a lottery, optionally filtered by buyer, grouped by owner, and/or with timestamps and signatures. */
|
|
327
329
|
GetTickets(
|
|
328
330
|
authority: HasPublicKey,
|
|
329
331
|
lotteryId: number,
|
|
330
332
|
buyer?: HasPublicKey | false,
|
|
331
333
|
group?: boolean,
|
|
332
|
-
time?: boolean
|
|
334
|
+
time?: boolean,
|
|
335
|
+
signature?: boolean
|
|
333
336
|
): Promise<TicketListResult>;
|
|
334
337
|
|
|
335
338
|
/**
|
|
@@ -399,8 +402,8 @@ declare module "solotto" {
|
|
|
399
402
|
ticketReceipt: PublicKey
|
|
400
403
|
): Promise<[PublicKey, number]>;
|
|
401
404
|
|
|
402
|
-
/** Derive the prize pool PDA. */
|
|
403
|
-
DerivePrizePoolPDA(): Promise<[PublicKey, number]>;
|
|
405
|
+
/** Derive the per-lottery prize pool PDA. Seeds: ["prize-pool", lotteryPDA]. */
|
|
406
|
+
DerivePrizePoolPDA(lotteryPDA: PublicKey): Promise<[PublicKey, number]>;
|
|
404
407
|
}
|
|
405
408
|
|
|
406
409
|
/**
|
package/solotto.js
CHANGED
|
@@ -276,6 +276,7 @@ class Lottery extends EventEmitter {
|
|
|
276
276
|
{ pubkey: new PublicKey(LOTTO.ticket.ticketReceipt), isSigner: false, isWritable: false },
|
|
277
277
|
{ pubkey: new PublicKey(LOTTO.ticket.ticketPda), isSigner: false, isWritable: false },
|
|
278
278
|
{ pubkey: new PublicKey(LOTTO.prizePoolAddress), isSigner: false, isWritable: true },
|
|
279
|
+
{ pubkey: new PublicKey(LOTTO.authority), isSigner: false, isWritable: true },
|
|
279
280
|
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
280
281
|
];
|
|
281
282
|
const ix = new TransactionInstruction({programId: this.program, keys, data: await claimData()});
|
|
@@ -441,7 +442,7 @@ class Lottery extends EventEmitter {
|
|
|
441
442
|
* @param {Number} lotteryId - Lottery Id
|
|
442
443
|
* @param {PublicKey} buyer - Ticket Buyer Optional
|
|
443
444
|
*/
|
|
444
|
-
async GetTickets(authority, lotteryId, buyer = false, group = false, time = false) {
|
|
445
|
+
async GetTickets(authority, lotteryId, buyer = false, group = false, time = false, signature = false) {
|
|
445
446
|
const [lotteryPDA] = await this.DeriveLotteryPDA(authority.publicKey, lotteryId);
|
|
446
447
|
const filters = [];
|
|
447
448
|
filters.push({dataSize: 104});
|
|
@@ -460,10 +461,10 @@ class Lottery extends EventEmitter {
|
|
|
460
461
|
newTicket.ticketNumber = parseInt(new BN(decoded.ticketNumber, 10, "le"));
|
|
461
462
|
newTicket.ticketPda = data.pubkey.toString();
|
|
462
463
|
newTicket.time = null;
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
}
|
|
464
|
+
let dat = null;
|
|
465
|
+
if(time || signature){dat = await this.connection.getSignaturesForAddress(data.pubkey, "finalized");}
|
|
466
|
+
if(time){newTicket.time = dat[0].blockTime;}
|
|
467
|
+
if(signature){newTicket.signature = dat[0].signature;}
|
|
467
468
|
tickets.push(newTicket);
|
|
468
469
|
i++;
|
|
469
470
|
}
|
|
@@ -586,8 +587,8 @@ class Lottery extends EventEmitter {
|
|
|
586
587
|
return Number(val);
|
|
587
588
|
});
|
|
588
589
|
}catch{}
|
|
589
|
-
const prizePoolAddress = await this.DerivePrizePoolPDA();
|
|
590
590
|
const lotteryAddress = await this.DeriveLotteryPDA(new PublicKey(auth), lotteryId);
|
|
591
|
+
const prizePoolAddress = await this.DerivePrizePoolPDA(lotteryAddress[0]);
|
|
591
592
|
let prizePoolBalance = prizePool;
|
|
592
593
|
if(fees){prizePoolBalance = prizePool - (prizePool * 0.1);}
|
|
593
594
|
return {
|
|
@@ -625,8 +626,8 @@ class Lottery extends EventEmitter {
|
|
|
625
626
|
programId
|
|
626
627
|
);
|
|
627
628
|
}
|
|
628
|
-
async DerivePrizePoolPDA() {
|
|
629
|
-
return PublicKey.findProgramAddressSync([Buffer.from("prize-pool")], this.program);
|
|
629
|
+
async DerivePrizePoolPDA(lotteryPDA) {
|
|
630
|
+
return PublicKey.findProgramAddressSync([Buffer.from("prize-pool"), lotteryPDA.toBuffer()], this.program);
|
|
630
631
|
}
|
|
631
632
|
|
|
632
633
|
/**
|
|
@@ -840,11 +841,13 @@ class LotteryManager {
|
|
|
840
841
|
return buffer;
|
|
841
842
|
}
|
|
842
843
|
const [lotteryPDA, bump] = await lottery.DeriveLotteryPDA(authority.publicKey, lotteryId);
|
|
844
|
+
const [prizePoolPDA] = await lottery.DerivePrizePoolPDA(lotteryPDA);
|
|
843
845
|
console.log("Lottery PDA:", lotteryPDA.toString());
|
|
844
846
|
const ix = new TransactionInstruction({
|
|
845
847
|
keys: [
|
|
846
848
|
{ pubkey: authority.publicKey, isSigner: true, isWritable: true },
|
|
847
849
|
{ pubkey: lotteryPDA, isSigner: false, isWritable: true },
|
|
850
|
+
{ pubkey: prizePoolPDA, isSigner: false, isWritable: true },
|
|
848
851
|
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
849
852
|
],
|
|
850
853
|
programId: this.program,
|
|
@@ -893,7 +896,7 @@ class LotteryManager {
|
|
|
893
896
|
const lottery = new Lottery(this.connection, false, this.program);
|
|
894
897
|
const network = new LotteryNetwork(this.connection);
|
|
895
898
|
const [lotteryPDA] = await lottery.DeriveLotteryPDA(authority.publicKey, lotteryId);
|
|
896
|
-
const [prizePoolPDA] = await lottery.DerivePrizePoolPDA();
|
|
899
|
+
const [prizePoolPDA] = await lottery.DerivePrizePoolPDA(lotteryPDA);
|
|
897
900
|
const keys = [
|
|
898
901
|
{ pubkey: authority.publicKey, isSigner: true, isWritable: false },
|
|
899
902
|
{ pubkey: lotteryPDA, isSigner: false, isWritable: true },
|