Skip to content

Commit 150b21a

Browse files
committed
SFT-3711: Implement new fee calculation.
1 parent 360a8bd commit 150b21a

File tree

6 files changed

+117
-55
lines changed

6 files changed

+117
-55
lines changed

extmod/foundation-rust/Cargo.lock

Lines changed: 40 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extmod/foundation-rust/include/foundation.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,23 +300,31 @@ typedef enum {
300300
VALIDATION_RESULT_INVALID_REDEEM_SCRIPT,
301301
VALIDATION_RESULT_UNSUPPORTED_SIGHASH,
302302
VALIDATION_RESULT_TXID_MISMATCH,
303+
VALIDATION_RESULT_MISSING_OUTPUT_POINT,
303304
VALIDATION_RESULT_MISSING_PREVIOUS_TXID,
304305
VALIDATION_RESULT_MISSING_REDEEM_WITNESS_SCRIPT,
305306
VALIDATION_RESULT_TAPROOT_OUTPUT_INVALID_PUBLIC_KEY,
307+
VALIDATION_RESULT_TOO_MANY_INPUTS,
306308
VALIDATION_RESULT_TOO_MANY_OUTPUTS,
307309
VALIDATION_RESULT_TOO_MANY_OUTPUT_KEYS,
308310
VALIDATION_RESULT_MULTIPLE_KEYS_NOT_EXPECTED,
309311
VALIDATION_RESULT_FRAUDULENT_OUTPUT_PUBLIC_KEY,
310312
VALIDATION_RESULT_MISSING_OUTPUT,
311313
VALIDATION_RESULT_UNKNOWN_OUTPUT_SCRIPT,
314+
VALIDATION_RESULT_FRAUDULENT_WITNESS_UTXO,
312315
} ValidationResult_Tag;
313316

314317
typedef struct {
315318
int64_t total_with_change;
316319
int64_t total_change;
317320
bool is_self_send;
321+
int64_t fee;
318322
} ValidationResult_Ok_Body;
319323

324+
typedef struct {
325+
uint64_t index;
326+
} ValidationResult_MissingOutputPoint_Body;
327+
320328
typedef struct {
321329
uint64_t index;
322330
} ValidationResult_MissingRedeemWitnessScript_Body;
@@ -345,17 +353,23 @@ typedef struct {
345353
uint64_t index;
346354
} ValidationResult_UnknownOutputScript_Body;
347355

356+
typedef struct {
357+
uint64_t index;
358+
} ValidationResult_FraudulentWitnessUtxo_Body;
359+
348360
typedef struct {
349361
ValidationResult_Tag tag;
350362
union {
351363
ValidationResult_Ok_Body OK;
364+
ValidationResult_MissingOutputPoint_Body MISSING_OUTPUT_POINT;
352365
ValidationResult_MissingRedeemWitnessScript_Body MISSING_REDEEM_WITNESS_SCRIPT;
353366
ValidationResult_TaprootOutputInvalidPublicKey_Body TAPROOT_OUTPUT_INVALID_PUBLIC_KEY;
354367
ValidationResult_TooManyOutputKeys_Body TOO_MANY_OUTPUT_KEYS;
355368
ValidationResult_MultipleKeysNotExpected_Body MULTIPLE_KEYS_NOT_EXPECTED;
356369
ValidationResult_FraudulentOutputPublicKey_Body FRAUDULENT_OUTPUT_PUBLIC_KEY;
357370
ValidationResult_MissingOutput_Body MISSING_OUTPUT;
358371
ValidationResult_UnknownOutputScript_Body UNKNOWN_OUTPUT_SCRIPT;
372+
ValidationResult_FraudulentWitnessUtxo_Body FRAUDULENT_WITNESS_UTXO;
359373
};
360374
} ValidationResult;
361375

extmod/foundation-rust/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ static LOGGER: Logger = Logger;
6262
#[export_name = "foundation_init_logger"]
6363
pub unsafe extern "C" fn init_logger() {
6464
log::set_logger_racy(&LOGGER)
65-
.map(|()| log::set_max_level(log::LevelFilter::Trace))
65+
.map(|()| log::set_max_level(log::LevelFilter::Debug))
6666
.expect("Failed to initialize logger")
6767
}

extmod/foundation-rust/src/psbt.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub enum ValidationResult {
4545
total_with_change: i64,
4646
total_change: i64,
4747
is_self_send: bool,
48+
fee: i64,
4849
},
4950
/// Internal error of the validation function.
5051
InternalError,
@@ -56,13 +57,17 @@ pub enum ValidationResult {
5657
InvalidRedeemScript,
5758
UnsupportedSighash,
5859
TxidMismatch,
60+
MissingOutputPoint {
61+
index: u64,
62+
},
5963
MissingPreviousTxid,
6064
MissingRedeemWitnessScript {
6165
index: u64,
6266
},
6367
TaprootOutputInvalidPublicKey {
6468
index: u64,
6569
},
70+
TooManyInputs,
6671
TooManyOutputs,
6772
TooManyOutputKeys {
6873
index: u64,
@@ -79,6 +84,9 @@ pub enum ValidationResult {
7984
UnknownOutputScript {
8085
index: u64,
8186
},
87+
FraudulentWitnessUtxo {
88+
index: u64,
89+
},
8290
}
8391

8492
impl From<ValidationError> for ValidationResult {
@@ -89,13 +97,17 @@ impl From<ValidationError> for ValidationResult {
8997
ValidationError::InvalidRedeemScript => Self::InvalidRedeemScript,
9098
ValidationError::UnsupportedSighash => Self::UnsupportedSighash,
9199
ValidationError::TxidMismatch => Self::TxidMismatch,
100+
ValidationError::MissingOutputPoint { index } => {
101+
Self::MissingOutputPoint { index }
102+
}
92103
ValidationError::MissingPreviousTxid => Self::MissingPreviousTxid,
93104
ValidationError::MissingRedeemWitnessScript { index } => {
94105
Self::MissingRedeemWitnessScript { index }
95106
}
96107
ValidationError::TaprootOutputInvalidPublicKey { index } => {
97108
Self::TaprootOutputInvalidPublicKey { index }
98109
}
110+
ValidationError::TooManyInputs => Self::TooManyInputs,
99111
ValidationError::TooManyOutputs => Self::TooManyOutputs,
100112
ValidationError::TooManyOutputKeys { index } => {
101113
Self::TooManyOutputKeys { index }
@@ -112,6 +124,9 @@ impl From<ValidationError> for ValidationResult {
112124
ValidationError::UnknownOutputScript { index } => {
113125
Self::UnknownOutputScript { index }
114126
}
127+
ValidationError::FraudulentWitnessUtxo { index } => {
128+
Self::FraudulentWitnessUtxo { index }
129+
}
115130
}
116131
}
117132
}
@@ -221,6 +236,7 @@ pub extern "C" fn validate(
221236
total_with_change: details.total_with_change,
222237
total_change: details.total_change,
223238
is_self_send: details.is_self_send(),
239+
fee: details.fee(),
224240
};
225241
true
226242
}

0 commit comments

Comments
 (0)