Skip to content

Commit cf53c3a

Browse files
author
CodeSandwich
committed
Add JCLI command for creating own stake delegation certificate
1 parent a4f65b6 commit cf53c3a

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

doc/stake_pool/delegating_stake.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,32 @@
22

33
## how to create the delegation certificate
44

5-
Stake is concentrated in accounts, and you will need your account public key to
6-
delegate its associated stake.
5+
Stake is concentrated in accounts, and you will need account public key to delegate its associated stake.
76

8-
You will need your:
7+
### for own account
8+
9+
You will need:
10+
11+
* the Stake Pool ID: an hexadecimal string identifying the stake pool you want
12+
to delegate your stake to.
13+
14+
```sh
15+
jcli certificate new owned-stake-delegation STAKE_POOL_ID > stake_delegation.cert
16+
```
17+
18+
Note that the certificate is in blaco, there's no account key used for its creation.
19+
In order for delegation to work it must be submitted to a node inside a very specific transaction:
20+
21+
* Transaction must have exactly 1 input
22+
* The input must be from account
23+
* The input value must be strictly equal to fee of the transaction
24+
* Transaction must have 0 outputs
25+
26+
The account used for input will have its stake delegated to the stake pool
27+
28+
### for any account
29+
30+
You will need:
931

1032
* account public key: a bech32 string of a public key
1133
* the Stake Pool ID: an hexadecimal string identifying the stake pool you want

jcli/src/jcli_app/certificate/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::path::{Path, PathBuf};
77
use structopt::StructOpt;
88

99
mod get_stake_pool_id;
10+
mod new_owner_stake_delegation;
1011
mod new_stake_delegation;
1112
mod new_stake_pool_registration;
1213
mod sign;
@@ -74,6 +75,8 @@ pub enum NewArgs {
7475
StakePoolRegistration(new_stake_pool_registration::StakePoolRegistration),
7576
/// build a stake delegation certificate
7677
StakeDelegation(new_stake_delegation::StakeDelegation),
78+
/// build an owner stake delegation certificate
79+
OwnerStakeDelegation(new_owner_stake_delegation::OwnerStakeDelegation),
7780
}
7881

7982
#[derive(StructOpt)]
@@ -99,6 +102,7 @@ impl NewArgs {
99102
match self {
100103
NewArgs::StakePoolRegistration(args) => args.exec()?,
101104
NewArgs::StakeDelegation(args) => args.exec()?,
105+
NewArgs::OwnerStakeDelegation(args) => args.exec()?,
102106
}
103107
Ok(())
104108
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use crate::jcli_app::certificate::{weighted_pool_ids::WeightedPoolIds, write_cert, Error};
2+
use chain_impl_mockchain::certificate::{Certificate, OwnerStakeDelegation as Delegation};
3+
use jormungandr_lib::interfaces::Certificate as CertificateType;
4+
use std::convert::TryInto;
5+
use std::ops::Deref;
6+
use std::path::PathBuf;
7+
use structopt::StructOpt;
8+
9+
#[derive(StructOpt)]
10+
pub struct OwnerStakeDelegation {
11+
#[structopt(flatten)]
12+
pool_ids: WeightedPoolIds,
13+
14+
/// write the output to the given file or print it to the standard output if not defined
15+
#[structopt(short = "o", long = "output")]
16+
output: Option<PathBuf>,
17+
}
18+
19+
impl OwnerStakeDelegation {
20+
pub fn exec(self) -> Result<(), Error> {
21+
let cert = Certificate::OwnerStakeDelegation(Delegation {
22+
delegation: (&self.pool_ids).try_into()?,
23+
});
24+
write_cert(
25+
self.output.as_ref().map(|x| x.deref()),
26+
CertificateType(cert),
27+
)
28+
}
29+
}

0 commit comments

Comments
 (0)