Spend
Mystiko Spend Related APIs.
Data Structures
quote
Retrieve quote information for a spend.
use mystiko_protos::api::handler::v1::{SpendQuoteRequest, SpendQuoteResponse};
use mystiko_protos::core::handler::v1::QuoteSpendOptions;
use mystiko_protos::common::v1::BridgeType;
use mystiko_protos::core::v1::SpendType;
use mystiko_lib::spend::quote;
use mystiko_protos::api::v1::api_response;
let options = QuoteSpendOptions::builder()
.chain_id(11155111_u64)
.asset_symbol("MTT".to_string())
.bridge_type(BridgeType::Loop as i32)
.spend_type(SpendType::Withdraw as i32)
.build();
let request = SpendQuoteRequest::builder().options(options).build();
let response = quote(request);
let spendQuote = match response.result {
Some(api_response::Result::Data(data)) => match SpendQuoteResponse::try_from(data) {
Ok(spendQuote) => spendQuote,
Err(e) => return Err(anyhow!(format!("Failed to parse response: {}", e))),
},
Some(api_response::Result::ErrorMessage(error)) => {
return Err(anyhow!(format!("API error: {}", error)));
}
None => {
return Err(anyhow!("No result found in response"));
}
};
QuoteSpendOptions
:
Parameter | Required | Description |
---|---|---|
chain_id | true | The chain ID of the asset. |
asset_symbol | true | The asset symbol. |
version | false | The version of the spend. |
amount | false | The amount of the spend. |
use_relayer | false | Whether to use a relayer. |
query_timeout_ms | false | The query timeout in milliseconds. |
spend_type | false | The type of spend. |
bridge_type | false | The bridge type. |
SpendQuote
data structure is as follows:
Property | Type | Description |
---|---|---|
valid | bool | Whether the quote is valid. |
asset_symbol | String | The asset symbol. |
asset_decimals | u32 | The asset decimals. |
current_balance | f64 | The current balance. |
current_decimal_balance | String | The current decimal balance. |
num_of_inputs | u64 | The number of inputs. |
num_of_outputs | u64 | The number of outputs. |
min_rollup_fee | f64 | The minimum rollup fee. |
min_rollup_fee_decimal | String | The minimum rollup fee decimal. |
rollup_fee_asset_symbol | String | The rollup fee asset symbol. |
rollup_fee_asset_decimals | u32 | The rollup fee asset decimals. |
fixed_amounts | Vec<f64> | The fixed amounts. |
fixed_decimal_amounts | Vec<String> | The fixed decimal amounts. |
selected_commitments | Vec<String> | The selected commitments. |
gas_relayers | Vec<GasRelayer> | The gas relayers. |
max_gas_relayer_fee | Option<f64> | The maximum gas relayer fee. |
max_gas_relayer_fee_decimal | Option<String> | The maximum gas relayer fee decimal. |
gas_relayer_fee_asset_symbol | Option<String> | The gas relayer fee asset symbol. |
gas_relayer_fee_asset_decimals | Option<u32> | The gas relayer fee asset decimals. |
invalid_code | Option<SpendInvalidCode> | The invalid code. |
amount_range | Option<AmountRange> | The amount range. |
summary
Retrieve summary information for a spend.
use mystiko_protos::api::handler::v1::{SpendSummaryRequest, SpendSummaryResponse};
use mystiko_protos::core::handler::v1::CreateSpendOptions;
use mystiko_protos::common::v1::BridgeType;
use mystiko_protos::core::v1::SpendType;
use mystiko_lib::spend::summary;
use mystiko_protos::api::v1::api_response;
let options = CreateSpendOptions::builder()
.chain_id(11155111_u64)
.asset_symbol("MTT".to_string())
.bridge_type(BridgeType::Loop as i32)
.spend_type(SpendType::Withdraw as i32)
.amount(12)
.recipient("0xFE500c274F72f1d1a9978c903d97E6d45CD9121B".to_string())
.wallet_password("password".to_string())
.build();
let request = SpendSummaryRequest::builder().options(options).build();
let response = summary(request);
let spendSummary = match response.result {
Some(api_response::Result::Data(data)) => match SpendSummaryResponse::try_from(data) {
Ok(spendSummary) => spendSummary,
Err(e) => return Err(anyhow!(format!("Failed to parse response: {}", e))),
},
Some(api_response::Result::ErrorMessage(error)) => {
return Err(anyhow!(format!("API error: {}", error)));
}
None => {
return Err(anyhow!("No result found in response"));
}
};
CreateSpendOptions
:
Parameter | Required | Description |
---|---|---|
chain_id | true | The chain ID of the asset. |
asset_symbol | true | The asset symbol. |
amount | true | The amount of the spend. |
recipient | true | The recipient address. |
wallet_password | true | The wallet password. |
version | false | The version of the spend. |
rollup_fee_amount | false | The rollup fee amount. |
gas_relayer | false | The gas relayer. |
query_timeout_ms | false | The query timeout in milliseconds. |
spend_quote | false | The spend quote. |
spend_type | false | The type of spend. |
bridge_type | false | The bridge type. |
SpendSummary
data structure is as follows:
Property | Type | Description |
---|---|---|
asset_symbol | String | The asset symbol. |
asset_decimals | u32 | The asset decimals. |
current_balance | f64 | The current balance. |
current_Decimal_Balance | String | The current decimal balance. |
new_Balance | f64 | The new balance. |
new_Decimal_Balance | String | The new decimal balance. |
amount | f64 | The amount. |
decimal_Amount | String | The decimal amount. |
recipient | String | The recipient address. |
rollup_Fee_Amount | f64 | The rollup fee amount. |
rollup_Fee_Decimal_Amount | String | The rollup fee decimal amount. |
rollup_Fee_Total_Amount | f64 | The rollup fee total amount. |
rollup_Fee_Total_Decimal_Amount | String | The rollup fee total decimal amount. |
rollup_Fee_Asset_Symbol | String | The rollup fee asset symbol. |
rollup_Fee_Asset_Decimals | u32 | The rollup fee asset decimals. |
gas_Relayer_Fee_Amount | Option<f64> | The gas relayer fee amount. |
gas_Relayer_Fee_Decimal_Amount | Option<String> | The gas relayer fee decimal amount. |
gas_Relayer_Fee_Asset_Symbol | Option<String> | The gas relayer fee asset symbol. |
gas_Relayer_Fee_Asset_Decimals | Option<u32> | The gas relayer fee asset decimals. |
gas_Relayer_Address | Option<String> | The gas relayer address. |
gas_Relayer_Name | Option<String> | The gas relayer name. |
gas_Relayer_Url | Option<String> | The gas relayer URL. |
create
Create a Spend request.
use mystiko_protos::api::handler::v1::{CreateSpendRequest, CreateSpendResponse};
use mystiko_protos::core::handler::v1::CreateSpendOptions;
use mystiko_protos::common::v1::BridgeType;
use mystiko_protos::core::v1::SpendType;
use mystiko_lib::spend::create;
use mystiko_protos::api::v1::api_response;
let options = CreateSpendOptions::builder()
.chain_id(11155111_u64)
.asset_symbol("MTT".to_string())
.bridge_type(BridgeType::Loop as i32)
.spend_type(SpendType::Withdraw as i32)
.amount(12)
.rollup_fee_amount(4.0)
.recipient("0xFE500c274F72f1d1a9978c903d97E6d45CD9121B".to_string())
.wallet_password("password".to_string())
.build();
let request = CreateSpendRequest::builder().options(options).build();
let response = create(request);
let spend = match response.result {
Some(api_response::Result::Data(data)) => match CreateSpendResponse::try_from(data) {
Ok(spend) => spend,
Err(e) => return Err(anyhow!(format!("Failed to parse response: {}", e))),
},
Some(api_response::Result::ErrorMessage(error)) => {
return Err(anyhow!(format!("API error: {}", error)));
}
None => {
return Err(anyhow!("No result found in response"));
}
};
Spend
data structure is as follows:
Property | Type | Description |
---|---|---|
id | String | The ID of the spend. |
created_at | u64 | The creation time of the spend. |
updated_at | u64 | The update time of the spend. |
chain_id | u64 | The chain ID of the asset. |
contract_address | String | The contract address. |
asset_symbol | String | The asset symbol. |
asset_decimals | u32 | The asset decimals. |
amount | f64 | The amount. |
decimal_amount | String | The decimal amount. |
recipient | String | The recipient address. |
wallet_id | String | The wallet ID. |
input_commitments | Vec<String> | The input commitments. |
output_commitments | Vec<String> | The output commitments. |
nullifiers | Vec<String> | The nullifiers. |
signature_public_key_hashes | Vec<String> | The signature public key hashes. |
encrypted_auditor_notes | Vec<String> | The encrypted auditor notes. |
rollup_fee_amount | Option<f64> | The rollup fee amount. |
rollup_fee_decimal_amount | Option<String> | The rollup fee decimal amount. |
rollup_fee_total_amount | Option<f64> | The rollup fee total amount. |
rollup_fee_total_decimal_amount | Option<String> | The rollup fee total decimal amount. |
gas_relayer_fee_amount | Option<f64> | The gas relayer fee amount. |
gas_relayer_fee_decimal_amount | Option<String> | The gas relayer fee decimal amount. |
signature_public_key | Option<String> | The signature public key. |
asset_address | Option<String> | The asset address. |
proof | Option<String> | The proof. |
root_hash | Option<String> | The root hash. |
gas_relayer_address | Option<String> | The gas relayer address. |
gas_relayer_url | Option<String> | The gas relayer URL. |
signature | Option<String> | The signature. |
random_auditing_public_key | Option<String> | The random auditing public key. |
error_message | Option<String> | The error message. |
transaction_hash | Option<String> | The transaction hash. |
bridge_type | BridgeType | The bridge type. |
spend_type | SpendType | The spend type. |
status | SpendStatus | The spend status. |
send
Send a spend transaction using a private key.
use mystiko_protos::api::handler::v1::{SendSpendRequest, SendSpendResponse};
use mystiko_protos::core::handler::v1::SendSpendOptions;
use mystiko_protos::common::v1::BridgeType;
use mystiko_protos::core::v1::SpendType;
use mystiko_lib::spend::send;
use mystiko_protos::api::v1::api_response;
let send_options = SendSpendOptions::builder()
.spend_id("spend id".to_string())
.wallet_password("P@ssw0rd".to_string())
.private_key("signer private key".to_string())
.query_timeout_ms(100_u64)
.spend_confirmations(10_u64)
.tx_send_timeout_ms(200_u64)
.tx_wait_interval_ms(10_u64)
.tx_wait_timeout_ms(300_u64)
.build();
let request = SendSpendRequest::builder().options(send_options).build();
let response = send(request);
let spend = match response.result {
Some(api_response::Result::Data(data)) => match SendSpendResponse::try_from(data) {
Ok(spend) => spend,
Err(e) => return Err(anyhow!(format!("Failed to parse response: {}", e))),
},
Some(api_response::Result::ErrorMessage(error)) => {
return Err(anyhow!(format!("API error: {}", error)));
}
None => {
return Err(anyhow!("No result found in response"));
}
};
SendSpendOptions
:
Parameter | Required | Description |
---|---|---|
spend_id | true | The ID of the spend. |
wallet_password | true | The wallet password. |
private_key | false | The private key. |
signer_provider | false | The signer provider. |
query_timeout_ms | false | The query timeout in milliseconds. |
spend_confirmations | false | The spend confirmations. |
tx_send_timeout_ms | false | The transaction send timeout in milliseconds. |
tx_wait_timeout_ms | false | The transaction wait timeout in milliseconds. |
tx_wait_interval_ms | false | The transaction wait interval in milliseconds. |
relayer_wait_timeout_ms | false | The relayer wait timeout in milliseconds. |
relayer_wait_interval_ms | false | The relayer wait interval in milliseconds. |
tx | false | The transaction. |
raw_merkle_tree | false | The raw Merkle tree. |
raw_zk_program | false | The raw ZK program. |
raw_zk_proving_key | false | The raw ZK proving key. |
raw_zk_verifying_key | false | The raw ZK verifying key. |
raw_zk_abi | false | The raw ZK ABI. |
send_with_grpc
Send a spend transaction by signing through the given gRPC interface.
use mystiko_protos::api::handler::v1::{SendSpendWithGrpcRequest, SendSpendResponse};
use mystiko_protos::core::handler::v1::SendSpendOptions;
use mystiko_protos::service::v1::ClientOptions;
use mystiko_protos::common::v1::BridgeType;
use mystiko_protos::core::v1::SpendType;
use mystiko_lib::spend::send_with_grpc;
use mystiko_protos::api::v1::api_response;
let send_options = SendSpendOptions::builder()
.spend_id("spend id".to_string())
.wallet_password("P@ssw0rd".to_string())
.query_timeout_ms(100_u64)
.spend_confirmations(10_u64)
.tx_send_timeout_ms(200_u64)
.tx_wait_interval_ms(10_u64)
.tx_wait_timeout_ms(300_u64)
.build();
let client_options = ClientOptions::builder().build();
let request = SendSpendWithGrpcRequest::builder().send_options(send_options).client_options(client_options).build();
let response = send_with_grpc(request);
let spend = match response.result {
Some(api_response::Result::Data(data)) => match SendSpendResponse::try_from(data) {
Ok(spend) => spend,
Err(e) => return Err(anyhow!(format!("Failed to parse response: {}", e))),
},
Some(api_response::Result::ErrorMessage(error)) => {
return Err(anyhow!(format!("API error: {}", error)));
}
None => {
return Err(anyhow!("No result found in response"));
}
};
ClientOptions
:
Parameter | Required | Description |
---|---|---|
host | true | Host. |
port | true | Port. |
is_ssl | false | Is SSL. |
ssl_cert | false | SSL cert. |
ssl_cert_path | false | SSL cert path. |
ssl_server_name | false | SSL server name. |
find
Query Spend data using Filter
.
use mystiko_protos::storage::v1::{QueryFilter, SubFilter};
use mystiko_protos::api::handler::v1::{FindSpendRequest, FindSpendResponse};
use mystiko_lib::spend::find;
use mystiko_protos::api::v1::api_response;
let filter = QueryFilter::from(SubFilter::equal(DocumentColumn::Id, "spend id".to_string()))
let request = FindSpendRequest::builder().filter(filter).build();
let response = find(request);
let spends = match response.result {
Some(api_response::Result::Data(data)) => match FindSpendResponse::try_from(data) {
Ok(spends) => spends,
Err(e) => return Err(anyhow!(format!("Failed to parse response: {}", e))),
},
Some(api_response::Result::ErrorMessage(error)) => {
return Err(anyhow!(format!("API error: {}", error)));
}
None => {
return Err(anyhow!("No result found in response"));
}
};
find_all
Query all Spend data.
use mystiko_protos::api::handler::v1::FindSpendResponse;
use mystiko_lib::spend::find_all;
use mystiko_protos::api::v1::api_response;
let response = find_all();
let spends = match response.result {
Some(api_response::Result::Data(data)) => match FindSpendResponse::try_from(data) {
Ok(spends) => spends,
Err(e) => return Err(anyhow!(format!("Failed to parse response: {}", e))),
},
Some(api_response::Result::ErrorMessage(error)) => {
return Err(anyhow!(format!("API error: {}", error)));
}
None => {
return Err(anyhow!("No result found in response"));
}
};
find_one
Find a single Spend record using Filter
.
use mystiko_protos::storage::v1::{QueryFilter, SubFilter};
use mystiko_protos::api::handler::v1::{FindSpendRequest, FindOneSpendResponse};
use mystiko_lib::spend::find_one;
use mystiko_protos::api::v1::api_response;
let filter = QueryFilter::from(SubFilter::equal(DocumentColumn::Id, "spend id".to_string()))
let request = FindSpendRequest::builder().filter(filter).build();
let response = find_one(request);
let spend = match response.result {
Some(api_response::Result::Data(data)) => match FindOneSpendResponse::try_from(data) {
Ok(spend) => spend,
Err(e) => return Err(anyhow!(format!("Failed to parse response: {}", e))),
},
Some(api_response::Result::ErrorMessage(error)) => {
return Err(anyhow!(format!("API error: {}", error)));
}
None => {
return Err(anyhow!("No result found in response"));
}
};
find_by_id
Find a single Spend record by its ID.
use mystiko_protos::api::handler::v1::FindOneSpendResponse;
use mystiko_lib::spend::find_by_id;
use mystiko_protos::api::v1::api_response;
let response = find_by_id("spend id".to_string());
let spend = match response.result {
Some(api_response::Result::Data(data)) => match FindOneSpendResponse::try_from(data) {
Ok(spend) => spend,
Err(e) => return Err(anyhow!(format!("Failed to parse response: {}", e))),
},
Some(api_response::Result::ErrorMessage(error)) => {
return Err(anyhow!(format!("API error: {}", error)));
}
None => {
return Err(anyhow!("No result found in response"));
}
};
count
Query the count of data that matches the Filter
criteria.
use mystiko_protos::storage::v1::{QueryFilter, SubFilter};
use mystiko_protos::api::handler::v1::CountSpendResponse;
use mystiko_lib::spend::count;
use mystiko_protos::api::v1::api_response;
let filter = QueryFilter::from(SubFilter::equal(DocumentColumn::Id, "spend id".to_string()))
let request = FindSpendRequest::builder().filter(filter).build();
let response = count(request);
let total = match response.result {
Some(api_response::Result::Data(data)) => match CountSpendResponse::try_from(data) {
Ok(total) => total,
Err(e) => return Err(anyhow!(format!("Failed to parse response: {}", e))),
},
Some(api_response::Result::ErrorMessage(error)) => {
return Err(anyhow!(format!("API error: {}", error)));
}
None => {
return Err(anyhow!("No result found in response"));
}
};
count_all
Query the total count of all Spend data.
use mystiko_protos::api::handler::v1::CountSpendResponse;
use mystiko_lib::spend::count_all;
use mystiko_protos::api::v1::api_response;
let response = count_all();
let total = match response.result {
Some(api_response::Result::Data(data)) => match CountSpendResponse::try_from(data) {
Ok(total) => total,
Err(e) => return Err(anyhow!(format!("Failed to parse response: {}", e))),
},
Some(api_response::Result::ErrorMessage(error)) => {
return Err(anyhow!(format!("API error: {}", error)));
}
None => {
return Err(anyhow!("No result found in response"));
}
};
update
Update a Spend record.
use mystiko_protos::api::handler::v1::{FindOneSpendResponse, UpdateSpendRequest, UpdateSpendResponse};
use mystiko_lib::spend::find_by_id;
use mystiko_lib::spend::update;
use mystiko_protos::api::v1::api_response;
let response = find_by_id("spend id".to_string());
let mut spend = match response.result {
Some(api_response::Result::Data(data)) => match FindOneSpendResponse::try_from(data) {
Ok(d) => d.spend.unwrap(),
Err(e) => return Err(anyhow!(format!("Failed to parse response: {}", e))),
},
Some(api_response::Result::ErrorMessage(error)) => {
return Err(anyhow!(format!("API error: {}", error)));
}
None => {
return Err(anyhow!("No result found in response"));
}
};
spend.amount = 2000;
let request = UpdateSpendRequest::builder().spend(spend).build();
let response = update(request);
let spend = match response.result {
Some(api_response::Result::Data(data)) => match UpdateSpendResponse::try_from(data) {
Ok(spend) => spend,
Err(e) => return Err(anyhow!(format!("Failed to parse response: {}", e))),
},
Some(api_response::Result::ErrorMessage(error)) => {
return Err(anyhow!(format!("API error: {}", error)));
}
None => {
return Err(anyhow!("No result found in response"));
}
};
update_batch
Batch update Spend records.
use mystiko_protos::api::handler::v1::{FindOneSpendResponse, UpdateSpendBatchRequest, UpdateSpendBatchResponse};
use mystiko_lib::spend::find_by_id;
use mystiko_lib::spend::update_batch;
use mystiko_protos::api::v1::api_response;
let response = find_by_id("spend id".to_string());
let mut spend = match response.result {
Some(api_response::Result::Data(data)) => match FindOneSpendResponse::try_from(data) {
Ok(d) => d.spend.unwrap(),
Err(e) => return Err(anyhow!(format!("Failed to parse response: {}", e))),
},
Some(api_response::Result::ErrorMessage(error)) => {
return Err(anyhow!(format!("API error: {}", error)));
}
None => {
return Err(anyhow!("No result found in response"));
}
};
spend.amount = 2000;
let request = UpdateSpendBatchRequest::builder().spends(vec![spend]).build();
let response = update_batch(request);
let spends = match response.result {
Some(api_response::Result::Data(data)) => match UpdateSpendBatchResponse::try_from(data) {
Ok(spends) => spends,
Err(e) => return Err(anyhow!(format!("Failed to parse response: {}", e))),
},
Some(api_response::Result::ErrorMessage(error)) => {
return Err(anyhow!(format!("API error: {}", error)));
}
None => {
return Err(anyhow!("No result found in response"));
}
};
update_by_filter
Update Spend records based on the conditions specified in the Filter
.
use mystiko_protos::storage::v1::{QueryFilter, SubFilter, ColumnValuePair};
use mystiko_protos::storage::v1::UpdateSpendByFilterRequest;
use mystiko_lib::spend::update_by_filter;
let filter = QueryFilter::from(SubFilter::equal(DocumentColumn::Id, "spend id".to_string()));
let values = vec![ColumnValuePair::builder().column("amount").value(2000_f64).build()];
let request = UpdateSpendByFilterRequest::builder().column_values(values).filter(filter).build();
let response = update_by_filter(request);
assert!(response.code.unwrap().success);
update_all
Update all Spend records.
use mystiko_protos::storage::v1::ColumnValuePair;
use mystiko_protos::storage::v1::UpdateAllSpendRequest;
use mystiko_lib::spend::update_all;
let values = vec![ColumnValuePair::builder().column("amount").value(2000_f64).build()];
let request = UpdateAllSpendRequest::builder().column_values(values).build();
let response = update_all(request);
assert!(response.code.unwrap().success);
delete
Delete a Spend record.
use mystiko_protos::storage::v1::DeleteSpendRequest;
use mystiko_lib::spend::delete;
let request = DeleteSpendRequest::builder().spend(spend).build();
let response = delete(request);
assert!(response.code.unwrap().success);
delete_batch
Batch delete Spend records.
use mystiko_protos::storage::v1::DeleteSpendBatchRequest;
use mystiko_lib::spend::delete_batch;
let request = DeleteSpendBatchRequest::builder().deposits(vec![spend]).build();
let response = delete_batch(request);
assert!(response.code.unwrap().success);
delete_by_filter
Delete Spend records based on the conditions specified in the Filter
.
use mystiko_protos::storage::v1::{QueryFilter, SubFilter};
use mystiko_protos::storage::v1::DeleteSpendByFilterRequest;
use mystiko_lib::spend::delete_by_filter;
let filter = QueryFilter::from(SubFilter::equal(DocumentColumn::Id, "spend id".to_string()));
let request = DeleteSpendByFilterRequest::builder().filter(filter).build();
let response = delete_by_filter(request);
assert!(response.code.unwrap().success);
delete_all
Delete all Spend records.
use mystiko_lib::spend::delete_all;
let response = delete_all();
assert!(response.code.unwrap().success);