1use crate::context_extension::ContextExtension;
4use crate::ergo_box::BoxId;
5use crate::prover_result;
6use ergo_lib::chain;
7use wasm_bindgen::prelude::*;
8
9extern crate derive_more;
10use derive_more::{From, Into};
11
12#[wasm_bindgen]
14#[derive(PartialEq, Eq, Debug, Clone, From, Into)]
15pub struct UnsignedInput(chain::transaction::UnsignedInput);
16
17#[wasm_bindgen]
18impl UnsignedInput {
19 #[wasm_bindgen(constructor)]
21 pub fn new(box_id: &BoxId, ext: &ContextExtension) -> Self {
22 UnsignedInput(chain::transaction::UnsignedInput {
23 box_id: box_id.clone().into(),
24 extension: ext.clone().into(),
25 })
26 }
27
28 pub fn from_box_id(box_id: &BoxId) -> Self {
31 UnsignedInput(chain::transaction::UnsignedInput {
32 box_id: box_id.clone().into(),
33 extension: ContextExtension::new().into(),
34 })
35 }
36
37 pub fn box_id(&self) -> BoxId {
39 self.0.box_id.into()
40 }
41
42 pub fn extension(&self) -> ContextExtension {
44 self.0.extension.clone().into()
45 }
46}
47
48#[wasm_bindgen]
50#[derive(PartialEq, Eq, Debug, Clone)]
51pub struct UnsignedInputs(Vec<UnsignedInput>);
52
53#[wasm_bindgen]
54impl UnsignedInputs {
55 #[wasm_bindgen(constructor)]
57 pub fn new() -> Self {
58 UnsignedInputs(vec![])
59 }
60
61 pub fn len(&self) -> usize {
63 self.0.len()
64 }
65
66 pub fn get(&self, index: usize) -> UnsignedInput {
68 self.0[index].clone()
69 }
70
71 pub fn add(&mut self, b: &UnsignedInput) {
73 self.0.push(b.clone());
74 }
75}
76
77impl From<&UnsignedInputs> for Vec<chain::transaction::UnsignedInput> {
78 fn from(v: &UnsignedInputs) -> Self {
79 v.0.clone().iter().map(|i| i.0.clone()).collect()
80 }
81}
82impl From<Vec<chain::transaction::UnsignedInput>> for UnsignedInputs {
83 fn from(v: Vec<chain::transaction::UnsignedInput>) -> Self {
84 UnsignedInputs(v.into_iter().map(UnsignedInput::from).collect())
85 }
86}
87
88#[wasm_bindgen]
90#[derive(PartialEq, Eq, Debug, Clone, From, Into)]
91pub struct Input(chain::transaction::Input);
92
93#[wasm_bindgen]
94impl Input {
95 pub fn box_id(&self) -> BoxId {
97 self.0.box_id.into()
98 }
99
100 pub fn spending_proof(&self) -> prover_result::ProverResult {
102 self.0.spending_proof.clone().into()
103 }
104}
105
106#[wasm_bindgen]
108#[derive(PartialEq, Eq, Debug, Clone)]
109pub struct Inputs(Vec<Input>);
110
111#[wasm_bindgen]
112impl Inputs {
113 #[wasm_bindgen(constructor)]
115 pub fn new() -> Self {
116 Inputs(vec![])
117 }
118
119 pub fn len(&self) -> usize {
121 self.0.len()
122 }
123
124 pub fn get(&self, index: usize) -> Input {
126 self.0[index].clone()
127 }
128}
129
130impl From<&Inputs> for Vec<chain::transaction::Input> {
131 fn from(v: &Inputs) -> Self {
132 v.0.clone().iter().map(|i| i.0.clone()).collect()
133 }
134}
135impl From<Vec<chain::transaction::Input>> for Inputs {
136 fn from(v: Vec<chain::transaction::Input>) -> Self {
137 Inputs(v.into_iter().map(Input::from).collect())
138 }
139}