Skip to content
This repository was archived by the owner on Dec 9, 2023. It is now read-only.

Commit 253a5b4

Browse files
authored
Merge pull request #120 from LNP-BP/i9n/import-list
I9n/import list
2 parents e5d1e45 + 3055425 commit 253a5b4

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

src/contracts/fungible/data/invoice.rs

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ pub enum OutpointDescriptor {
5252
}
5353

5454
#[derive(Clone, PartialEq, Eq, Debug)]
55+
#[cfg_attr(
56+
feature = "serde",
57+
derive(Serialize, Deserialize,),
58+
serde(crate = "serde_crate")
59+
)]
5560
pub enum Outpoint {
5661
BlindedUtxo(OutpointHash),
5762
Address(bitcoin::Address),

src/contracts/fungible/runtime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ impl Runtime {
318318
) -> Result<Reply, ServiceErrorDomain> {
319319
debug!("Got SYNC");
320320
let data = self.cacher.export(Some(data_format))?;
321-
Ok(Reply::Sync(reply::SyncFormat(self.config.format, data)))
321+
Ok(Reply::Sync(reply::SyncFormat(data_format, data)))
322322
}
323323

324324
async fn rpc_assets(

src/i9n/fungible.rs

+31-17
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ use lnpbp::bp;
2323
use lnpbp::bp::psbt::ProprietaryKeyMap;
2424
use lnpbp::lnp::presentation::Encode;
2525
use lnpbp::lnp::{Session, Unmarshall};
26-
use lnpbp::rgb::{AtomicValue, Consignment, ContractId, PSBT_OUT_PUBKEY};
26+
use lnpbp::rgb::{
27+
AtomicValue, Consignment, ContractId, Genesis, PSBT_OUT_PUBKEY,
28+
};
2729

2830
use super::{Error, Runtime};
2931
use crate::api::{
@@ -141,7 +143,7 @@ impl Runtime {
141143
let out_file = File::create(&transaction_file)
142144
.expect("can't create output transaction file");
143145
transfer.psbt.consensus_encode(out_file)?;
144-
println!(
146+
info!(
145147
"Transfer succeeded, consignment data are written to {:?}, partially signed witness transaction to {:?}",
146148
consignment_file, transaction_file
147149
);
@@ -165,8 +167,7 @@ impl Runtime {
165167
match &*self.command(Request::Accept(api))? {
166168
Reply::Failure(failure) => Err(Error::Reply(failure.clone())),
167169
Reply::Success => {
168-
println!("Accept succeeded");
169-
170+
info!("Accept command succeeded");
170171
Ok(())
171172
}
172173
_ => Err(Error::UnexpectedResponse),
@@ -177,8 +178,7 @@ impl Runtime {
177178
match &*self.command(Request::Validate(consignment))? {
178179
Reply::Failure(failure) => Err(Error::Reply(failure.clone())),
179180
Reply::Success => {
180-
println!("Validate succeeded");
181-
181+
info!("Validation succeeded");
182182
Ok(())
183183
}
184184
_ => Err(Error::UnexpectedResponse),
@@ -191,11 +191,7 @@ impl Runtime {
191191
) -> Result<BTreeMap<OutPoint, Vec<AtomicValue>>, Error> {
192192
match &*self.command(Request::Allocations(contract_id))? {
193193
Reply::Failure(failure) => Err(Error::Reply(failure.clone())),
194-
Reply::Allocations(response) => {
195-
println!("Asset allocations succeeded");
196-
197-
Ok(response.clone())
198-
}
194+
Reply::Allocations(response) => Ok(response.clone()),
199195
_ => Err(Error::UnexpectedResponse),
200196
}
201197
}
@@ -206,22 +202,40 @@ impl Runtime {
206202
) -> Result<BTreeMap<ContractId, Vec<AtomicValue>>, Error> {
207203
match &*self.command(Request::Assets(outpoint))? {
208204
Reply::Failure(failure) => Err(Error::Reply(failure.clone())),
209-
Reply::Assets(response) => {
210-
println!("Outpoint assets succeeded");
205+
Reply::Assets(response) => Ok(response.clone()),
206+
_ => Err(Error::UnexpectedResponse),
207+
}
208+
}
211209

212-
Ok(response.clone())
210+
pub fn export_asset(
211+
&mut self,
212+
asset_id: ContractId,
213+
) -> Result<Genesis, Error> {
214+
match &*self.command(Request::ExportAsset(asset_id))? {
215+
Reply::Failure(failure) => Err(Error::Reply(failure.clone())),
216+
Reply::Genesis(response) => Ok(response.clone()),
217+
_ => Err(Error::UnexpectedResponse),
218+
}
219+
}
220+
221+
pub fn import_asset(&mut self, genesis: Genesis) -> Result<(), Error> {
222+
match &*self.command(Request::ImportAsset(genesis))? {
223+
Reply::Failure(failure) => Err(Error::Reply(failure.clone())),
224+
Reply::Success => {
225+
info!("Asset import succeeded");
226+
Ok(())
213227
}
214228
_ => Err(Error::UnexpectedResponse),
215229
}
216230
}
217231

218-
pub fn sync(
232+
pub fn list_assets(
219233
&mut self,
220234
data_format: DataFormat,
221235
) -> Result<reply::SyncFormat, Error> {
222236
match &*self.command(Request::Sync(data_format))? {
223-
Reply::Sync(data) => Ok(data.clone()),
224-
Reply::Failure(failmsg) => Err(Error::Reply(failmsg.clone())),
237+
Reply::Failure(failure) => Err(Error::Reply(failure.clone())),
238+
Reply::Sync(response) => Ok(response.clone()),
225239
_ => Err(Error::UnexpectedResponse),
226240
}
227241
}

0 commit comments

Comments
 (0)