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
// RGB standard library
// Written in 2020 by
//     Dr. Maxim Orlovsky <orlovsky@pandoracore.com>
//
// To the extent possible under law, the author(s) have dedicated all
// copyright and related and neighboring rights to this software to
// the public domain worldwide. This software is distributed without
// any warranty.
//
// You should have received a copy of the MIT License
// along with this software.
// If not, see <https://opensource.org/licenses/MIT>.

use std::collections::BTreeMap;

use lnpbp::bitcoin::util::psbt::PartiallySignedTransaction as Psbt;
use lnpbp::bitcoin::OutPoint;
use lnpbp::bp::blind::{OutpointHash, OutpointReveal};
use lnpbp::rgb::{Consignment, ContractId, NodeId, Transition};

#[derive(Clone, Debug, Display, LnpApi)]
#[lnp_api(encoding = "strict")]
#[display(Debug)]
#[non_exhaustive]
pub enum Request {
    #[lnp_api(type = 0x0101)]
    AddSchema(::lnpbp::rgb::Schema),

    #[lnp_api(type = 0x0103)]
    ListSchemata(),

    #[lnp_api(type = 0x0105)]
    ReadSchema(::lnpbp::rgb::SchemaId),

    #[lnp_api(type = 0x0201)]
    AddGenesis(::lnpbp::rgb::Genesis),

    #[lnp_api(type = 0x0203)]
    ListGeneses(),

    #[lnp_api(type = 0x0205)]
    ReadGenesis(::lnpbp::rgb::ContractId),

    #[lnp_api(type = 0x0301)]
    ReadTransitions(Vec<::lnpbp::rgb::NodeId>),

    #[lnp_api(type = 0x0401)]
    Consign(crate::api::stash::ConsignRequest),

    #[lnp_api(type = 0x0403)]
    Validate(::lnpbp::rgb::Consignment),

    #[lnp_api(type = 0x0405)]
    Merge(crate::api::stash::MergeRequest),

    #[lnp_api(type = 0x0407)]
    Forget(Vec<(::lnpbp::rgb::NodeId, u16)>),
}

#[derive(Clone, StrictEncode, StrictDecode, Debug, Display)]
#[display(Debug)]
pub struct ConsignRequest {
    pub contract_id: ContractId,
    pub inputs: Vec<OutPoint>,
    pub transition: Transition,
    pub other_transition_ids: BTreeMap<ContractId, NodeId>,
    pub outpoints: Vec<OutpointHash>,
    pub psbt: Psbt,
}

#[derive(Clone, StrictEncode, StrictDecode, Debug, Display)]
#[display(Debug)]
pub struct MergeRequest {
    pub consignment: Consignment,
    pub reveal_outpoints: Vec<OutpointReveal>,
}