Skip to content

Commit

Permalink
Added participant_type to get_info.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zshan0 committed Apr 7, 2022
1 parent 43071cf commit 24de726
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Display general information about the current daemon state.
| `vaults` | integer | Current number of vaults (unconfirmed are included) |
| `managers_threshold` | integer | Number of managers needed for spending the `unvault_tx` |
| `descriptors` | object | Three `string` entries: `deposit`, `unvault` and `cpfp` for the three Miniscript descriptors |

| `participant_type` | string | Answer can be `stakeholder`, `manager`, `stakeholdermanager` |

### `getdepositaddress`

Expand Down
14 changes: 13 additions & 1 deletion src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod utils;
pub use crate::{
bitcoind::{interface::WalletTransaction, BitcoindError},
communication::ServerStatus,
revaultd::{BlockchainTip, VaultStatus},
revaultd::{BlockchainTip, UserRole, VaultStatus},
};
use crate::{
communication::{
Expand Down Expand Up @@ -268,6 +268,15 @@ impl DaemonControl {
})
.count();

assert!(revaultd.is_stakeholder() || revaultd.is_manager());
let participant_type = if revaultd.is_manager() && revaultd.is_stakeholder() {
UserRole::StakeholderManager
} else if revaultd.is_manager() {
UserRole::Manager
} else {
UserRole::Stakeholder
};

GetInfoResult {
version: VERSION.to_string(),
network: revaultd.bitcoind_config.network,
Expand All @@ -280,6 +289,7 @@ impl DaemonControl {
unvault: revaultd.unvault_descriptor.clone(),
cpfp: revaultd.cpfp_descriptor.clone(),
},
participant_type,
}
}

Expand Down Expand Up @@ -1430,6 +1440,8 @@ pub struct GetInfoResult {
pub vaults: usize,
pub managers_threshold: usize,
pub descriptors: GetInfoDescriptors,
#[serde(serialize_with = "ser_to_string", deserialize_with = "deser_from_str")]
pub participant_type: UserRole,
}

/// Information about a vault.
Expand Down
27 changes: 27 additions & 0 deletions src/revaultd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,33 @@ pub enum UserRole {
StakeholderManager,
}

impl FromStr for UserRole {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"stakeholder" => Ok(Self::Stakeholder),
"stakeholdermanager" => Ok(Self::StakeholderManager),
"manager" => Ok(Self::Manager),
_ => Err(format!("Unknown role: {}", s)),
}
}
}

impl fmt::Display for UserRole {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}",
match *self {
Self::Stakeholder => "stakeholder",
Self::Manager => "manager",
Self::StakeholderManager => "stakeholdermanager",
}
)
}
}

/// Our global state
pub struct RevaultD {
// Bitcoind stuff
Expand Down
1 change: 1 addition & 0 deletions tests/test_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def test_getinfo(revaultd_manager, bitcoind):
assert res["vaults"] == 0
# revaultd_manager always deploys with N = 2, M = 3, threshold = M
assert res["managers_threshold"] == 3
assert res["participant_type"] == "manager"
# test descriptors: RPC call & which Revaultd's were configured
assert res["descriptors"]["cpfp"] == revaultd_manager.cpfp_desc
assert res["descriptors"]["deposit"] == revaultd_manager.deposit_desc
Expand Down

0 comments on commit 24de726

Please sign in to comment.