Skip to content

Commit 74ffa34

Browse files
allow set_donation and set_current_treasury_value on tx builder
1 parent 9f0133e commit 74ffa34

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

chain/rust/src/builders/tx_builder.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,8 @@ pub struct TransactionBuilder {
435435
utxos: Vec<InputBuilderResult>,
436436
collateral_return: Option<TransactionOutput>,
437437
reference_inputs: Option<Vec<TransactionUnspentOutput>>,
438+
donation: Option<Coin>,
439+
current_treasury_value: Option<Coin>,
438440
}
439441

440442
impl TransactionBuilder {
@@ -911,6 +913,14 @@ impl TransactionBuilder {
911913
self.fee = Some(fee)
912914
}
913915

916+
pub fn set_donation(&mut self, donation: Coin) {
917+
self.donation = Some(donation)
918+
}
919+
920+
pub fn set_current_treasury_value(&mut self, current_treasury_value: Coin) {
921+
self.current_treasury_value = Some(current_treasury_value)
922+
}
923+
914924
pub fn set_ttl(&mut self, ttl: Slot) {
915925
self.ttl = Some(ttl)
916926
}
@@ -1125,6 +1135,8 @@ impl TransactionBuilder {
11251135
utxos: Vec::new(),
11261136
collateral_return: None,
11271137
reference_inputs: None,
1138+
donation: None,
1139+
current_treasury_value: None,
11281140
}
11291141
}
11301142

@@ -1243,12 +1255,16 @@ impl TransactionBuilder {
12431255
.map_err(Into::into)
12441256
}
12451257

1246-
/// Return explicit output plus implicit output plus burn (does not consider fee directly)
1258+
/// Return explicit output plus implicit output plus burn/donation (does not consider fee directly)
12471259
pub fn get_total_output(&self) -> Result<Value, TxBuilderError> {
12481260
let (_, burn_value) = self.get_mint_as_values();
12491261
self.get_explicit_output()?
12501262
.checked_add(&Value::from(self.get_deposit()?))
12511263
.and_then(|x| x.checked_add(&burn_value))
1264+
.and_then(|x| match self.donation {
1265+
Some(donation) => x.checked_add(&Value::from(donation)),
1266+
None => Ok(x),
1267+
})
12521268
.map_err(Into::into)
12531269
}
12541270

@@ -1405,8 +1421,8 @@ impl TransactionBuilder {
14051421
.proposals
14061422
.as_ref()
14071423
.map(|proposals| proposals.clone().into()),
1408-
current_treasury_value: None,
1409-
donation: None,
1424+
current_treasury_value: self.current_treasury_value,
1425+
donation: self.donation,
14101426
encodings: None,
14111427
};
14121428

chain/wasm/src/builders/tx_builder.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,14 @@ impl TransactionBuilder {
201201
self.0.set_fee(fee)
202202
}
203203

204+
pub fn set_donation(&mut self, donation: Coin) {
205+
self.0.set_donation(donation)
206+
}
207+
208+
pub fn set_current_treasury_value(&mut self, current_treasury_value: Coin) {
209+
self.0.set_current_treasury_value(current_treasury_value)
210+
}
211+
204212
pub fn set_ttl(&mut self, ttl: Slot) {
205213
self.0.set_ttl(ttl)
206214
}

0 commit comments

Comments
 (0)