Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom nonce in requested payments #121

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions crates/chia-sdk-offers/src/offer_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,24 @@ impl OfferBuilder<Make> {
/// Adds a list of requested payments for a given puzzle.
/// It will use the nonce to create a new [`NotarizedPayment`] and add it to the requested payments.
pub fn request<P>(
self,
ctx: &mut SpendContext,
puzzle: &P,
payments: Vec<Payment>,
) -> Result<Self, DriverError>
where
P: ToClvm<Allocator>,
{
let nonce = self.data.nonce;
self.request_with_nonce(ctx, puzzle, nonce, payments)
}

/// Adds a list of payments in a [`NotarizedPayment`] for a given puzzle and nonce.
pub fn request_with_nonce<P>(
mut self,
ctx: &mut SpendContext,
puzzle: &P,
nonce: Bytes32,
payments: Vec<Payment>,
) -> Result<Self, DriverError>
where
Expand All @@ -56,10 +71,7 @@ impl OfferBuilder<Make> {
let puzzle_hash = ctx.tree_hash(puzzle_ptr).into();
let puzzle = Puzzle::parse(&ctx.allocator, puzzle_ptr);

let notarized_payment = NotarizedPayment {
nonce: self.data.nonce,
payments,
};
let notarized_payment = NotarizedPayment { nonce, payments };
let notarized_payment_ptr = ctx.alloc(&notarized_payment)?;
let notarized_payment_hash = ctx.tree_hash(notarized_payment_ptr);

Expand Down