1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
use regex::Regex;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use lnpbp::bitcoin::util::psbt::PartiallySignedTransaction;
use lnpbp::bitcoin::OutPoint;
use lnpbp::bp::blind::OutpointReveal;
use lnpbp::rgb::{Consignment, ContractId};
use crate::fungible::{ConsealCoins, OutpointCoins, SealCoins};
use crate::DataFormat;
#[derive(Clone, Debug, Display, LnpApi)]
#[lnp_api(encoding = "strict")]
#[display(Debug)]
#[non_exhaustive]
pub enum Request {
#[lnp_api(type = 0x0101)]
Issue(crate::api::fungible::Issue),
#[lnp_api(type = 0x0103)]
Transfer(crate::api::fungible::TransferApi),
#[lnp_api(type = 0x0105)]
Validate(::lnpbp::rgb::Consignment),
#[lnp_api(type = 0x0107)]
Accept(crate::api::fungible::AcceptApi),
#[lnp_api(type = 0x0109)]
ImportAsset(::lnpbp::rgb::Genesis),
#[lnp_api(type = 0x010b)]
ExportAsset(::lnpbp::rgb::ContractId),
#[lnp_api(type = 0x010d)]
Forget(::lnpbp::bitcoin::OutPoint),
#[lnp_api(type = 0xFF01)]
Sync(DataFormat),
#[lnp_api(type = 0xFF02)]
Assets(OutPoint),
#[lnp_api(type = 0xFF03)]
Allocations(ContractId),
}
#[derive(
Clap, Clone, PartialEq, StrictEncode, StrictDecode, Debug, Display,
)]
#[display(Debug)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize,),
serde(crate = "serde_crate")
)]
pub struct Issue {
#[clap(validator=ticker_validator)]
pub ticker: String,
pub name: String,
#[clap(short, long)]
pub description: Option<String>,
#[clap(short, long, default_value = "0")]
pub precision: u8,
pub allocation: Vec<OutpointCoins>,
#[clap(short, long)]
pub inflation: Vec<OutpointCoins>,
#[clap(short, long)]
pub renomination: Option<OutPoint>,
#[clap(short, long)]
pub epoch: Option<OutPoint>,
}
#[derive(Clone, PartialEq, StrictEncode, StrictDecode, Debug, Display)]
#[display(Debug)]
pub struct TransferApi {
pub contract_id: ContractId,
pub psbt: PartiallySignedTransaction,
pub inputs: Vec<OutPoint>,
pub ours: Vec<SealCoins>,
pub theirs: Vec<ConsealCoins>,
}
#[derive(Clone, StrictEncode, StrictDecode, Debug, Display)]
#[display(Debug)]
pub struct AcceptApi {
pub consignment: Consignment,
pub reveal_outpoints: Vec<OutpointReveal>,
}
fn ticker_validator(name: &str) -> Result<(), String> {
let re = Regex::new(r"^[A-Z]{3,8}$").expect("Regex parse failure");
if !re.is_match(&name) {
Err(
"Ticker name must be between 3 and 8 chars, contain no spaces and \
consist only of capital letters\
"
.to_string(),
)
} else {
Ok(())
}
}