|
@@ -19,7 +19,7 @@
|
|
|
use darkfi_sdk::{
|
|
use darkfi_sdk::{
|
|
|
crypto::{pasta_prelude::Field, smt::EMPTY_NODES_FP, ContractId, MerkleNode, MerkleTree},
|
|
crypto::{pasta_prelude::Field, smt::EMPTY_NODES_FP, ContractId, MerkleNode, MerkleTree},
|
|
|
dark_tree::DarkLeaf,
|
|
dark_tree::DarkLeaf,
|
|
|
- error::ContractResult,
|
|
|
|
|
|
|
+ error::{ContractError, ContractResult},
|
|
|
msg,
|
|
msg,
|
|
|
pasta::pallas,
|
|
pasta::pallas,
|
|
|
wasm, ContractCall,
|
|
wasm, ContractCall,
|
|
@@ -40,6 +40,12 @@ use crate::{
|
|
|
MONEY_CONTRACT_NULLIFIER_ROOTS_TREE, MONEY_CONTRACT_TOKEN_FREEZE_TREE,
|
|
MONEY_CONTRACT_NULLIFIER_ROOTS_TREE, MONEY_CONTRACT_TOKEN_FREEZE_TREE,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+fn parse_money_function(data: &[u8]) -> Result<MoneyFunction, ContractError> {
|
|
|
|
|
+ let Some(func) = data.first() else { return Err(ContractError::InvalidFunction) };
|
|
|
|
|
+
|
|
|
|
|
+ MoneyFunction::try_from(*func)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/// `Money::Fee` functions
|
|
/// `Money::Fee` functions
|
|
|
mod fee_v1;
|
|
mod fee_v1;
|
|
|
use fee_v1::{
|
|
use fee_v1::{
|
|
@@ -230,7 +236,7 @@ fn get_metadata(cid: ContractId, ix: &[u8]) -> ContractResult {
|
|
|
let call_idx = wasm::util::get_call_index()? as usize;
|
|
let call_idx = wasm::util::get_call_index()? as usize;
|
|
|
let calls: Vec<DarkLeaf<ContractCall>> = deserialize(ix)?;
|
|
let calls: Vec<DarkLeaf<ContractCall>> = deserialize(ix)?;
|
|
|
let self_ = &calls[call_idx].data;
|
|
let self_ = &calls[call_idx].data;
|
|
|
- let func = MoneyFunction::try_from(self_.data[0])?;
|
|
|
|
|
|
|
+ let func = parse_money_function(&self_.data)?;
|
|
|
|
|
|
|
|
let metadata = match func {
|
|
let metadata = match func {
|
|
|
MoneyFunction::FeeV1 => {
|
|
MoneyFunction::FeeV1 => {
|
|
@@ -263,7 +269,7 @@ fn process_instruction(cid: ContractId, ix: &[u8]) -> ContractResult {
|
|
|
let call_idx = wasm::util::get_call_index()? as usize;
|
|
let call_idx = wasm::util::get_call_index()? as usize;
|
|
|
let calls: Vec<DarkLeaf<ContractCall>> = deserialize(ix)?;
|
|
let calls: Vec<DarkLeaf<ContractCall>> = deserialize(ix)?;
|
|
|
let self_ = &calls[call_idx].data;
|
|
let self_ = &calls[call_idx].data;
|
|
|
- let func = MoneyFunction::try_from(self_.data[0])?;
|
|
|
|
|
|
|
+ let func = parse_money_function(&self_.data)?;
|
|
|
|
|
|
|
|
let update_data = match func {
|
|
let update_data = match func {
|
|
|
MoneyFunction::FeeV1 => {
|
|
MoneyFunction::FeeV1 => {
|
|
@@ -302,7 +308,7 @@ fn process_instruction(cid: ContractId, ix: &[u8]) -> ContractResult {
|
|
|
/// is the update data retrieved from `process_instruction()`, prefixed with the
|
|
/// is the update data retrieved from `process_instruction()`, prefixed with the
|
|
|
/// contract function.
|
|
/// contract function.
|
|
|
fn process_update(cid: ContractId, update_data: &[u8]) -> ContractResult {
|
|
fn process_update(cid: ContractId, update_data: &[u8]) -> ContractResult {
|
|
|
- match MoneyFunction::try_from(update_data[0])? {
|
|
|
|
|
|
|
+ match parse_money_function(update_data)? {
|
|
|
MoneyFunction::FeeV1 => {
|
|
MoneyFunction::FeeV1 => {
|
|
|
let update: MoneyFeeUpdateV1 = deserialize(&update_data[1..])?;
|
|
let update: MoneyFeeUpdateV1 = deserialize(&update_data[1..])?;
|
|
|
Ok(money_fee_process_update_v1(cid, update)?)
|
|
Ok(money_fee_process_update_v1(cid, update)?)
|