use crate::context_extension::ContextExtension;
use crate::ergo_box::BoxId;
use crate::prover_result;
use ergo_lib::chain;
use wasm_bindgen::prelude::*;
extern crate derive_more;
use derive_more::{From, Into};
#[wasm_bindgen]
#[derive(PartialEq, Eq, Debug, Clone, From, Into)]
pub struct UnsignedInput(chain::transaction::UnsignedInput);
#[wasm_bindgen]
impl UnsignedInput {
#[wasm_bindgen(constructor)]
pub fn new(box_id: &BoxId, ext: &ContextExtension) -> Self {
UnsignedInput(chain::transaction::UnsignedInput {
box_id: box_id.clone().into(),
extension: ext.clone().into(),
})
}
pub fn from_box_id(box_id: &BoxId) -> Self {
UnsignedInput(chain::transaction::UnsignedInput {
box_id: box_id.clone().into(),
extension: ContextExtension::new().into(),
})
}
pub fn box_id(&self) -> BoxId {
self.0.box_id.into()
}
pub fn extension(&self) -> ContextExtension {
self.0.extension.clone().into()
}
}
#[wasm_bindgen]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct UnsignedInputs(Vec<UnsignedInput>);
#[wasm_bindgen]
impl UnsignedInputs {
#[wasm_bindgen(constructor)]
pub fn new() -> Self {
UnsignedInputs(vec![])
}
pub fn len(&self) -> usize {
self.0.len()
}
pub fn get(&self, index: usize) -> UnsignedInput {
self.0[index].clone()
}
pub fn add(&mut self, b: &UnsignedInput) {
self.0.push(b.clone());
}
}
impl From<&UnsignedInputs> for Vec<chain::transaction::UnsignedInput> {
fn from(v: &UnsignedInputs) -> Self {
v.0.clone().iter().map(|i| i.0.clone()).collect()
}
}
impl From<Vec<chain::transaction::UnsignedInput>> for UnsignedInputs {
fn from(v: Vec<chain::transaction::UnsignedInput>) -> Self {
UnsignedInputs(v.into_iter().map(UnsignedInput::from).collect())
}
}
#[wasm_bindgen]
#[derive(PartialEq, Eq, Debug, Clone, From, Into)]
pub struct Input(chain::transaction::Input);
#[wasm_bindgen]
impl Input {
pub fn box_id(&self) -> BoxId {
self.0.box_id.into()
}
pub fn spending_proof(&self) -> prover_result::ProverResult {
self.0.spending_proof.clone().into()
}
}
#[wasm_bindgen]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct Inputs(Vec<Input>);
#[wasm_bindgen]
impl Inputs {
#[wasm_bindgen(constructor)]
pub fn new() -> Self {
Inputs(vec![])
}
pub fn len(&self) -> usize {
self.0.len()
}
pub fn get(&self, index: usize) -> Input {
self.0[index].clone()
}
}
impl From<&Inputs> for Vec<chain::transaction::Input> {
fn from(v: &Inputs) -> Self {
v.0.clone().iter().map(|i| i.0.clone()).collect()
}
}
impl From<Vec<chain::transaction::Input>> for Inputs {
fn from(v: Vec<chain::transaction::Input>) -> Self {
Inputs(v.into_iter().map(Input::from).collect())
}
}