pchain_types/
runtime.rs

1/*
2    Copyright © 2023, ParallelChain Lab 
3    Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
4*/
5
6//! Inputs of transaction commands as structures.
7
8use crate::serialization::{Serializable, Deserializable};
9use crate::cryptography::PublicAddress;
10
11#[derive(Debug, Clone, PartialEq, Eq, borsh::BorshSerialize, borsh::BorshDeserialize)]
12pub struct TransferInput {
13    /// Recipient of the transfer
14    pub recipient: PublicAddress,
15
16    /// The amount to transfer
17    pub amount: u64
18}
19
20impl Serializable for TransferInput {}
21impl Deserializable for TransferInput {}
22
23#[derive(Debug, Clone, PartialEq, Eq, borsh::BorshSerialize, borsh::BorshDeserialize)]
24pub struct DeployInput {
25    /// Smart contract in format of WASM bytecode
26    pub contract: Vec<u8>,
27
28    /// Version of Contract Binary Interface
29    pub cbi_version: u32
30}
31
32impl Serializable for DeployInput {}
33impl Deserializable for DeployInput {}
34
35#[derive(Debug, Clone, PartialEq, Eq, borsh::BorshSerialize, borsh::BorshDeserialize)]
36pub struct CallInput {
37    /// The address of the target contract
38    pub target: PublicAddress,
39
40    /// The method to be invoked
41    pub method: String,
42
43    /// The arguments supplied to the invoked method. It is a list of serialized method arguments (see [Serializable])
44    pub arguments: Option<Vec<Vec<u8>>>,
45
46    /// The amount sent to the target contract. The invoked contract can check the received amount 
47    /// by host function `amount()` according to the CBI.
48    pub amount: Option<u64>
49}
50
51impl Serializable for CallInput {}
52impl Deserializable for CallInput {}
53
54#[derive(Debug, Clone, PartialEq, Eq, borsh::BorshSerialize, borsh::BorshDeserialize)]
55pub struct CreatePoolInput {
56    /// Commission rate (in unit of percentage) is the portion that 
57    /// the owners of its delegated stakes should pay from the reward in an epoch transaction.
58    pub commission_rate: u8
59}
60
61impl Serializable for CreatePoolInput {}
62impl Deserializable for CreatePoolInput {}
63
64#[derive(Debug, Clone, PartialEq, Eq, borsh::BorshSerialize, borsh::BorshDeserialize)]
65pub struct SetPoolSettingsInput {
66    /// Commission rate (in unit of percentage) is the portion that 
67    /// the owners of its delegated stakes should pay from the reward in an epoch transaction.
68    pub commission_rate: u8,
69}
70
71impl Serializable for SetPoolSettingsInput {}
72impl Deserializable for SetPoolSettingsInput {}
73
74#[derive(Debug, Clone, PartialEq, Eq, borsh::BorshSerialize, borsh::BorshDeserialize)]
75pub struct CreateDepositInput {
76    /// The address of operator of the target pool
77    pub operator: PublicAddress,
78
79    /// The deposit amount
80    pub balance: u64,
81
82    /// Flag to indicate whether the received reward in epoch transaction should be automatically
83    /// staked to the pool
84    pub auto_stake_rewards: bool,
85}
86
87impl Serializable for CreateDepositInput {}
88impl Deserializable for CreateDepositInput {} 
89
90#[derive(Debug, Clone, PartialEq, Eq, borsh::BorshSerialize, borsh::BorshDeserialize)]
91pub struct SetDepositSettingsInput {
92    /// The address of operator of the target pool
93    pub operator: PublicAddress,
94
95    /// Flag to indicate whether the received reward in epoch transaction should be automatically
96    /// staked to the pool
97    pub auto_stake_rewards: bool,
98}
99
100impl Serializable for SetDepositSettingsInput {}
101impl Deserializable for SetDepositSettingsInput {}
102
103#[derive(Debug, Clone, PartialEq, Eq, borsh::BorshSerialize, borsh::BorshDeserialize)]
104pub struct TopUpDepositInput {
105    /// The address of operator of the target pool
106    pub operator: PublicAddress,
107
108    /// The amount added to Deposit's Balance
109    pub amount: u64,
110}
111
112impl Serializable for TopUpDepositInput {}
113impl Deserializable for TopUpDepositInput {}
114
115#[derive(Debug, Clone, PartialEq, Eq, borsh::BorshSerialize, borsh::BorshDeserialize)]
116pub struct WithdrawDepositInput {
117    /// The address of operator of the target pool
118    pub operator: PublicAddress,
119
120    /// The amount of deposits that the stake owner wants to withdraw. The prefix 'max'
121    /// is denoted here because the actual withdrawal amount can be less than 
122    /// the wanted amount.
123    pub max_amount: u64,
124}
125
126impl Serializable for WithdrawDepositInput {}
127impl Deserializable for WithdrawDepositInput {}
128
129#[derive(Debug, Clone, PartialEq, Eq, borsh::BorshSerialize, borsh::BorshDeserialize)]
130pub struct StakeDepositInput {
131    /// The address of operator of the target pool
132    pub operator: PublicAddress,
133
134    /// The amount of stakes that the stake owner wants to stake to the target pool. 
135    /// The prefix 'max' is denoted here because the actual amount to be staked
136    /// can be less than the wanted amount.
137    pub max_amount: u64,
138}
139
140impl Serializable for StakeDepositInput {}
141impl Deserializable for StakeDepositInput {}
142
143#[derive(Debug, Clone, PartialEq, Eq, borsh::BorshSerialize, borsh::BorshDeserialize)]
144pub struct UnstakeDepositInput {
145    /// The address of operator of the target pool
146    pub operator: PublicAddress,
147
148    /// The amount of stakes that the stake owner wants to remove from the target pool. 
149    /// The prefix 'max' is denoted here because the actual amount to be removed
150    /// can be less than the wanted amount.
151    pub max_amount: u64,
152}
153
154impl Serializable for UnstakeDepositInput {}
155impl Deserializable for UnstakeDepositInput {}