1use amplify::confinement;
25use chrono::{DateTime, Utc};
26use strict_types::{StrictVal, TypeName};
27use ultrasonic::Consensus;
28
29use crate::{CallRequest, CallState, Endpoint, Layer1, MethodName, StateName};
30
31impl<T, A> CallRequest<T, A> {
32 pub fn bitcoin_mainnet(scope: T, auth: A, data: Option<StrictVal>) -> Self {
33 Self::new(scope, Consensus::Bitcoin, false, auth, data)
34 }
35
36 pub fn bitcoin_testnet(scope: T, auth: A, data: Option<StrictVal>) -> Self {
37 Self::new(scope, Consensus::Bitcoin, true, auth, data)
38 }
39
40 pub fn liquid_mainnet(scope: T, auth: A, data: Option<StrictVal>) -> Self {
41 Self::new(scope, Consensus::Liquid, false, auth, data)
42 }
43
44 pub fn liquid_testnet(scope: T, auth: A, data: Option<StrictVal>) -> Self {
45 Self::new(scope, Consensus::Liquid, true, auth, data)
46 }
47
48 pub fn new(scope: T, consensus: Consensus, testnet: bool, auth: A, data: Option<StrictVal>) -> Self {
49 Self {
50 scope,
51 layer1: Layer1::new(consensus, testnet),
52 api: None,
53 call: None,
54 auth,
55 data,
56 lock: None,
57 expiry: None,
58 endpoints: Default::default(),
59 unknown_query: Default::default(),
60 }
61 }
62
63 pub fn use_api(mut self, api: impl Into<TypeName>) -> Self {
64 self.api = Some(api.into());
65 self
66 }
67
68 pub fn use_method(mut self, method: MethodName) -> Self {
69 if let Some(call) = &mut self.call {
70 call.method = method;
71 } else {
72 self.call = Some(CallState::new(method));
73 }
74 self
75 }
76
77 pub fn use_state(mut self, state: StateName) -> Self {
78 let mut call = self
79 .call
80 .expect("use_method must be called before use_state");
81 call.owned = Some(state);
82 self.call = Some(call);
83 self
84 }
85
86 pub fn use_expiry(mut self, expiry: DateTime<Utc>) -> Self {
87 self.expiry = Some(expiry);
88 self
89 }
90
91 pub fn add_endpoint(mut self, endpoint: Endpoint) -> Result<Self, confinement::Error> {
92 self.endpoints.push(endpoint)?;
93 Ok(self)
94 }
95}