Skip to content

Commit f9cf584

Browse files
committed
rename *Dapp type hierarchy to *Eip12;
1 parent aab2357 commit f9cf584

File tree

4 files changed

+36
-36
lines changed

4 files changed

+36
-36
lines changed

bindings/ergo-lib-wasm/src/ergo_box.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use wasm_bindgen::prelude::*;
2424

2525
use crate::ast::Constant;
2626
use crate::ergo_tree::ErgoTree;
27-
use crate::json::ErgoBoxJsonDapp;
27+
use crate::json::ErgoBoxJsonEip12;
2828
use crate::token::Tokens;
2929
use crate::utils::I64;
3030
use crate::{contract::Contract, transaction::TxId};
@@ -173,7 +173,7 @@ impl ErgoBox {
173173
/// JSON representation according to EIP-12 https://github.com/ergoplatform/eips/pull/23
174174
/// (similar to [`Self::to_json`], but with box value and token amount encoding as strings)
175175
pub fn to_js_eip12(&self) -> Result<JsValue, JsValue> {
176-
let box_dapp: ErgoBoxJsonDapp = self.0.clone().into();
176+
let box_dapp: ErgoBoxJsonEip12 = self.0.clone().into();
177177
JsValue::from_serde(&box_dapp).map_err(|e| JsValue::from_str(&format!("{}", e)))
178178
}
179179

bindings/ergo-lib-wasm/src/json.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! JSON serialization using strings for BoxValue and TokenAmount
1+
//! JSON serialization according to EIP-12 (using strings for BoxValue and TokenAmount)
22
33
use derive_more::FromStr;
44
use ergo_lib::chain::ergo_box::BoxId;
@@ -17,7 +17,7 @@ use ergo_lib::ergotree_ir::ergo_tree::ErgoTree;
1717
use serde::Serialize;
1818

1919
#[derive(Serialize, PartialEq, Debug, Clone)]
20-
pub(crate) struct TransactionJsonDapp {
20+
pub(crate) struct TransactionJsonEip12 {
2121
#[cfg_attr(feature = "json", serde(rename = "id"))]
2222
pub tx_id: TxId,
2323
/// inputs, that will be spent by this transaction.
@@ -29,12 +29,12 @@ pub(crate) struct TransactionJsonDapp {
2929
#[cfg_attr(feature = "json", serde(rename = "dataInputs"))]
3030
pub data_inputs: Vec<DataInput>,
3131
#[cfg_attr(feature = "json", serde(rename = "outputs"))]
32-
pub outputs: Vec<ErgoBoxJsonDapp>,
32+
pub outputs: Vec<ErgoBoxJsonEip12>,
3333
}
3434

35-
impl From<Transaction> for TransactionJsonDapp {
35+
impl From<Transaction> for TransactionJsonEip12 {
3636
fn from(t: Transaction) -> Self {
37-
TransactionJsonDapp {
37+
TransactionJsonEip12 {
3838
tx_id: t.id(),
3939
inputs: t.inputs,
4040
data_inputs: t.data_inputs,
@@ -44,7 +44,7 @@ impl From<Transaction> for TransactionJsonDapp {
4444
}
4545

4646
#[derive(Serialize, PartialEq, Debug, Clone)]
47-
pub(crate) struct UnsignedTransactionJsonDapp {
47+
pub(crate) struct UnsignedTransactionJsonEip12 {
4848
/// unsigned inputs, that will be spent by this transaction.
4949
#[cfg_attr(feature = "json", serde(rename = "inputs"))]
5050
pub inputs: Vec<UnsignedInput>,
@@ -55,28 +55,28 @@ pub(crate) struct UnsignedTransactionJsonDapp {
5555
pub data_inputs: Vec<DataInput>,
5656
/// box candidates to be created by this transaction
5757
#[cfg_attr(feature = "json", serde(rename = "outputs"))]
58-
pub outputs: Vec<ErgoBoxCandidateJsonDapp>,
58+
pub outputs: Vec<ErgoBoxCandidateJsonEip12>,
5959
}
6060

61-
impl From<UnsignedTransaction> for UnsignedTransactionJsonDapp {
61+
impl From<UnsignedTransaction> for UnsignedTransactionJsonEip12 {
6262
fn from(_: UnsignedTransaction) -> Self {
6363
todo!()
6464
}
6565
}
6666

6767
#[derive(Serialize, PartialEq, Eq, Debug, Clone)]
68-
pub(crate) struct ErgoBoxJsonDapp {
68+
pub(crate) struct ErgoBoxJsonEip12 {
6969
#[serde(rename = "boxId", alias = "id")]
7070
pub box_id: Option<BoxId>,
7171
/// amount of money associated with the box
7272
#[serde(rename = "value")]
73-
pub value: BoxValueJsonDapp,
73+
pub value: BoxValueJsonEip12,
7474
/// guarding script, which should be evaluated to true in order to open this box
7575
#[serde(rename = "ergoTree", with = "ergo_lib::chain::json::ergo_tree")]
7676
pub ergo_tree: ErgoTree,
7777
/// secondary tokens the box contains
7878
#[serde(rename = "assets")]
79-
pub tokens: Vec<TokenJsonDapp>,
79+
pub tokens: Vec<TokenJsonEip12>,
8080
/// additional registers the box can carry over
8181
#[serde(rename = "additionalRegisters")]
8282
pub additional_registers: NonMandatoryRegisters,
@@ -93,9 +93,9 @@ pub(crate) struct ErgoBoxJsonDapp {
9393
pub index: u16,
9494
}
9595

96-
impl From<ErgoBox> for ErgoBoxJsonDapp {
96+
impl From<ErgoBox> for ErgoBoxJsonEip12 {
9797
fn from(b: ErgoBox) -> Self {
98-
ErgoBoxJsonDapp {
98+
ErgoBoxJsonEip12 {
9999
box_id: b.box_id().into(),
100100
value: b.value.into(),
101101
ergo_tree: b.ergo_tree,
@@ -112,15 +112,15 @@ impl From<ErgoBox> for ErgoBoxJsonDapp {
112112
/// that will be calculated after full transaction formation.
113113
/// Use [`box_builder::ErgoBoxCandidateBuilder`] to create an instance.
114114
#[derive(Serialize, PartialEq, Eq, Clone, Debug)]
115-
pub(crate) struct ErgoBoxCandidateJsonDapp {
115+
pub(crate) struct ErgoBoxCandidateJsonEip12 {
116116
/// amount of money associated with the box
117117
#[serde(rename = "value")]
118-
pub value: BoxValueJsonDapp,
118+
pub value: BoxValueJsonEip12,
119119
/// guarding script, which should be evaluated to true in order to open this box
120120
#[serde(rename = "ergoTree", with = "ergo_lib::chain::json::ergo_tree")]
121121
pub ergo_tree: ErgoTree,
122122
#[serde(rename = "assets")]
123-
pub tokens: Vec<TokenJsonDapp>,
123+
pub tokens: Vec<TokenJsonEip12>,
124124
/// additional registers the box can carry over
125125
#[serde(rename = "additionalRegisters")]
126126
pub additional_registers: NonMandatoryRegisters,
@@ -136,38 +136,38 @@ pub(crate) struct ErgoBoxCandidateJsonDapp {
136136
serde::Serialize, serde::Deserialize, PartialEq, Eq, Hash, Debug, Clone, Copy, FromStr,
137137
)]
138138
/// Box value in nanoERGs with bound checks
139-
pub(crate) struct BoxValueJsonDapp(#[serde_as(as = "serde_with::DisplayFromStr")] u64);
139+
pub(crate) struct BoxValueJsonEip12(#[serde_as(as = "serde_with::DisplayFromStr")] u64);
140140

141-
impl From<BoxValue> for BoxValueJsonDapp {
141+
impl From<BoxValue> for BoxValueJsonEip12 {
142142
fn from(bv: BoxValue) -> Self {
143-
BoxValueJsonDapp(*bv.as_u64())
143+
BoxValueJsonEip12(*bv.as_u64())
144144
}
145145
}
146146

147147
/// Token represented with token id paired with it's amount
148148
#[derive(Serialize, PartialEq, Eq, Debug, Clone)]
149-
pub struct TokenJsonDapp {
149+
pub struct TokenJsonEip12 {
150150
/// token id
151151
#[serde(rename = "tokenId")]
152152
pub token_id: TokenId,
153153
/// token amount
154154
#[serde(rename = "amount")]
155-
pub amount: TokenAmountJsonDapp,
155+
pub amount: TokenAmountJsonEip12,
156156
}
157157

158-
impl From<Token> for TokenJsonDapp {
158+
impl From<Token> for TokenJsonEip12 {
159159
fn from(t: Token) -> Self {
160-
TokenJsonDapp {
160+
TokenJsonEip12 {
161161
token_id: t.token_id,
162-
amount: TokenAmountJsonDapp(t.amount.as_u64()),
162+
amount: TokenAmountJsonEip12(t.amount.as_u64()),
163163
}
164164
}
165165
}
166166

167167
/// Token amount with bound checks
168168
#[serde_with::serde_as]
169169
#[derive(Serialize, PartialEq, Eq, Hash, Debug, Clone, Copy, PartialOrd, Ord)]
170-
pub struct TokenAmountJsonDapp(
170+
pub struct TokenAmountJsonEip12(
171171
// Encodes as string always
172172
#[serde_as(as = "serde_with::DisplayFromStr")] u64,
173173
);

bindings/ergo-lib-wasm/src/token.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use ergo_lib::chain::Digest32;
88
use wasm_bindgen::prelude::*;
99

1010
use crate::ergo_box::BoxId;
11-
use crate::json::TokenJsonDapp;
11+
use crate::json::TokenJsonEip12;
1212
use crate::utils::I64;
1313

1414
/// Token id (32 byte digest)
@@ -107,10 +107,10 @@ impl Token {
107107
.map_err(|e| JsValue::from_str(&format!("{}", e)))
108108
}
109109

110-
/// JSON representation (same as [`Self::to_json`],
111-
/// but with box value and token amount encoding as strings)
112-
pub fn to_json_dapp(&self) -> Result<JsValue, JsValue> {
113-
let t_dapp: TokenJsonDapp = self.0.clone().into();
110+
/// JSON representation according to EIP-12 https://github.com/ergoplatform/eips/pull/23
111+
/// (similar to [`Self::to_json`], but with box value and token amount encoding as strings)
112+
pub fn to_js_eip12(&self) -> Result<JsValue, JsValue> {
113+
let t_dapp: TokenJsonEip12 = self.0.clone().into();
114114
JsValue::from_serde(&t_dapp).map_err(|e| JsValue::from_str(&format!("{}", e)))
115115
}
116116
}

bindings/ergo-lib-wasm/src/transaction.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::box_coll::ErgoBoxCandidates;
44
use crate::box_coll::ErgoBoxes;
55
use crate::data_input::DataInputs;
66
use crate::input::{Inputs, UnsignedInputs};
7-
use crate::json::TransactionJsonDapp;
8-
use crate::json::UnsignedTransactionJsonDapp;
7+
use crate::json::TransactionJsonEip12;
8+
use crate::json::UnsignedTransactionJsonEip12;
99
use ergo_lib::chain;
1010
use std::convert::TryFrom;
1111
use std::convert::TryInto;
@@ -80,7 +80,7 @@ impl Transaction {
8080
/// JSON representation according to EIP-12 https://github.com/ergoplatform/eips/pull/23
8181
/// (similar to [`Self::to_json`], but with box value and token amount encoding as strings)
8282
pub fn to_js_eip12(&self) -> Result<JsValue, JsValue> {
83-
let tx_dapp: TransactionJsonDapp = self.0.clone().into();
83+
let tx_dapp: TransactionJsonEip12 = self.0.clone().into();
8484
JsValue::from_serde(&tx_dapp).map_err(|e| JsValue::from_str(&format!("{}", e)))
8585
}
8686

@@ -155,7 +155,7 @@ impl UnsignedTransaction {
155155
/// JSON representation according to EIP-12 https://github.com/ergoplatform/eips/pull/23
156156
/// (similar to [`Self::to_json`], but with box value and token amount encoding as strings)
157157
pub fn to_js_eip12(&self) -> Result<JsValue, JsValue> {
158-
let tx_dapp: UnsignedTransactionJsonDapp = self.0.clone().into();
158+
let tx_dapp: UnsignedTransactionJsonEip12 = self.0.clone().into();
159159
JsValue::from_serde(&tx_dapp).map_err(|e| JsValue::from_str(&format!("{}", e)))
160160
}
161161

0 commit comments

Comments
 (0)