sapio_base/plugin_args.rs
1// Copyright Judica, Inc 2022
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
7//! arguments for passing into a sapio module
8use crate::effects::MapEffectDB;
9use schemars::JsonSchema;
10use serde::{Deserialize, Serialize};
11
12/// a remote derivation for the network definitions
13#[derive(Serialize, Deserialize, JsonSchema)]
14#[serde(remote = "bitcoin::Network")]
15pub enum NetworkDef {
16 /// Classic Bitcoin
17 Bitcoin,
18 /// Bitcoin's testnet
19 Testnet,
20 /// Bitcoin's signet
21 Signet,
22 /// Bitcoin's regtest
23 Regtest,
24}
25
26/// # Arguments For Creating this Contract
27/// Provide this information to create an instance of a contract
28#[derive(Serialize, Deserialize, JsonSchema, Clone, Debug)]
29pub struct CreateArgs<S> {
30 /// # The Main Contract Arguments
31 pub arguments: S,
32 /// # Contextual Arguments
33 /// Others arguments set by general system settings
34 pub context: ContextualArguments,
35}
36
37/// # Contextual Arguments For Creating this Contract
38#[derive(Serialize, Deserialize, JsonSchema, Clone, Debug)]
39pub struct ContextualArguments {
40 #[serde(with = "NetworkDef")]
41 /// # The Network the contract should be created for.
42 pub network: bitcoin::Network,
43 #[serde(with = "bitcoin::util::amount::serde::as_sat")]
44 #[schemars(with = "u64")]
45 /// # The Amount of Funds Available to the Contract as Bitcoin.
46 pub amount: bitcoin::util::amount::Amount,
47
48 /// # Effects to augment compilations with
49 #[serde(skip_serializing_if = "MapEffectDB::skip_serializing", default)]
50 pub effects: MapEffectDB,
51}