|
44 | 44 | //! ``` |
45 | 45 | //! |
46 | 46 |
|
47 | | -use crate::runtime::params::RuntimeParamsEnvelope; |
48 | | -use crate::runtime::{get_finalizer_spec_key, WalletRuntimeConfig}; |
49 | | -use crate::{AmountFilter, AssetFilter, AssetVariant, FinalizerSpec, InputBlinder, InputIssuance, InputIssuanceKind, InputSchema, LockFilter, UTXOSource, WalletAbiError, WalletSourceFilter}; |
| 47 | +use crate::runtime::{WalletRuntimeConfig, get_finalizer_spec_key}; |
| 48 | +use crate::{ |
| 49 | + AmountFilter, AssetFilter, AssetVariant, FinalizerSpec, InputBlinder, InputIssuance, |
| 50 | + InputIssuanceKind, InputSchema, LockFilter, RuntimeParams, UTXOSource, WalletAbiError, |
| 51 | + WalletSourceFilter, |
| 52 | +}; |
50 | 53 |
|
51 | 54 | use std::collections::{BTreeMap, HashMap, HashSet}; |
52 | 55 |
|
53 | 56 | use lwk_wollet::elements::confidential::{Asset, AssetBlindingFactor, Value, ValueBlindingFactor}; |
54 | 57 | use lwk_wollet::elements::hashes::Hash; |
55 | 58 | use lwk_wollet::elements::pset::{Input, PartiallySignedTransaction}; |
56 | | -use lwk_wollet::elements::{secp256k1_zkp, AssetId, ContractHash, OutPoint, TxOut, TxOutSecrets}; |
57 | | -use lwk_wollet::{WalletTxOut, EC}; |
| 59 | +use lwk_wollet::elements::{AssetId, ContractHash, OutPoint, TxOut, TxOutSecrets, secp256k1_zkp}; |
| 60 | +use lwk_wollet::{EC, WalletTxOut}; |
58 | 61 |
|
59 | 62 | type CandidateScore = (u64, u64, u64, String, u32); |
60 | 63 |
|
@@ -92,7 +95,7 @@ struct ResolvedInputMaterial { |
92 | 95 | /// add_balance(&mut balances, "L-BTC", 2).unwrap(); |
93 | 96 | /// assert_eq!(balances.get("L-BTC"), Some(&12)); |
94 | 97 | /// ``` |
95 | | -fn add_balance( |
| 98 | +pub(super) fn add_balance( |
96 | 99 | map: &mut BTreeMap<AssetId, u64>, |
97 | 100 | asset_id: AssetId, |
98 | 101 | amount_sat: u64, |
@@ -190,7 +193,7 @@ fn validate_output_input_index( |
190 | 193 | /// assert_eq!(derive(3, InputIssuanceKind::Reissue(base)), base); |
191 | 194 | /// assert_ne!(derive(3, InputIssuanceKind::New(base)), base); |
192 | 195 | /// ``` |
193 | | -fn derive_issuance_entropy(outpoint: OutPoint, issuance: &InputIssuance) -> Midstate { |
| 196 | +pub(super) fn derive_issuance_entropy(outpoint: OutPoint, issuance: &InputIssuance) -> Midstate { |
194 | 197 | match issuance.kind { |
195 | 198 | InputIssuanceKind::New => AssetId::generate_asset_entropy( |
196 | 199 | outpoint, |
@@ -256,13 +259,13 @@ fn apply_issuance_to_pset_input( |
256 | 259 | Some(issuance.token_amount_sat) |
257 | 260 | }; |
258 | 261 |
|
259 | | - if let InputIssuanceKind::Reissue = issuance.kind { |
| 262 | + if issuance.kind == InputIssuanceKind::Reissue { |
260 | 263 | // TODO: investigate the purpose of this field, and make it functionally correct. |
261 | 264 | let mut nonce = secrets.asset_bf.into_inner(); |
262 | 265 | if nonce == secp256k1_zkp::ZERO_TWEAK { |
263 | 266 | let mut one = [0u8; 32]; |
264 | 267 | one[0] = 1; |
265 | | - nonce = secp256k1_zkp::Tweak::from_slice(&one).expect("tweak from [0,..,1] is correct") |
| 268 | + nonce = secp256k1_zkp::Tweak::from_slice(&one).expect("tweak from [0,..,1] is correct"); |
266 | 269 | } |
267 | 270 | pset_input.issuance_blinding_nonce = Some(nonce); |
268 | 271 | } |
@@ -374,7 +377,7 @@ impl WalletRuntimeConfig { |
374 | 377 | /// Build demand from output specs and store issuance-linked entries as deferred. |
375 | 378 | fn resolve_output_demands( |
376 | 379 | &self, |
377 | | - params: &RuntimeParamsEnvelope, |
| 380 | + params: &RuntimeParams, |
378 | 381 | state: &mut ResolutionState, |
379 | 382 | ) -> Result<(), WalletAbiError> { |
380 | 383 | // Convert output-level asset requirements into equation demand. |
@@ -533,12 +536,16 @@ impl WalletRuntimeConfig { |
533 | 536 | let mut pset_input = Input::from_prevout(material.outpoint); |
534 | 537 | pset_input.sequence = Some(input.sequence); |
535 | 538 | pset_input.witness_utxo = Some(material.tx_out.clone()); |
| 539 | + pset_input.amount = Some(material.secrets.value); |
| 540 | + pset_input.asset = Some(material.secrets.asset); |
536 | 541 |
|
537 | 542 | if let Some(issuance) = input.issuance.as_ref() { |
538 | 543 | apply_issuance_to_pset_input(&mut pset_input, issuance, &material.secrets)?; |
539 | 544 | } |
540 | 545 |
|
541 | | - pset_input.proprietary.insert(get_finalizer_spec_key(), input.finalizer.encode()); |
| 546 | + pset_input |
| 547 | + .proprietary |
| 548 | + .insert(get_finalizer_spec_key(), input.finalizer.encode()); |
542 | 549 | pst.add_input(pset_input); |
543 | 550 |
|
544 | 551 | Ok(()) |
@@ -615,7 +622,7 @@ impl WalletRuntimeConfig { |
615 | 622 | fn resolve_declared_inputs( |
616 | 623 | &self, |
617 | 624 | pst: &mut PartiallySignedTransaction, |
618 | | - params: &RuntimeParamsEnvelope, |
| 625 | + params: &RuntimeParams, |
619 | 626 | wallet_snapshot: &[WalletTxOut], |
620 | 627 | state: &mut ResolutionState, |
621 | 628 | ) -> Result<(), WalletAbiError> { |
@@ -697,7 +704,11 @@ impl WalletRuntimeConfig { |
697 | 704 | let tx_out = self.fetch_tx_out(&selected.outpoint)?; |
698 | 705 | let mut pset_input = Input::from_prevout(selected.outpoint); |
699 | 706 | pset_input.witness_utxo = Some(tx_out); |
700 | | - pset_input.proprietary.insert(get_finalizer_spec_key(), FinalizerSpec::Wallet.encode()); |
| 707 | + pset_input.amount = Some(selected.unblinded.value); |
| 708 | + pset_input.asset = Some(selected.unblinded.asset); |
| 709 | + pset_input |
| 710 | + .proprietary |
| 711 | + .insert(get_finalizer_spec_key(), FinalizerSpec::Wallet.encode()); |
701 | 712 | pst.add_input(pset_input); |
702 | 713 |
|
703 | 714 | add_balance( |
@@ -772,7 +783,7 @@ impl WalletRuntimeConfig { |
772 | 783 | pub(super) fn resolve_inputs( |
773 | 784 | &self, |
774 | 785 | pst: PartiallySignedTransaction, |
775 | | - params: &RuntimeParamsEnvelope, |
| 786 | + params: &RuntimeParams, |
776 | 787 | ) -> Result<PartiallySignedTransaction, WalletAbiError> { |
777 | 788 | // Phase 1: initialize demand/supply state and load wallet snapshot once. |
778 | 789 | // We keep all equation state in a dedicated struct so each phase mutates a single object. |
|
0 commit comments