Skip to content

Commit

Permalink
Merge pull request #148 from Artemkaaas/pool-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewwhitehead authored Feb 2, 2023
2 parents 14dad40 + 2305194 commit 01c8dd4
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
45 changes: 45 additions & 0 deletions libindy_vdr/src/ffi/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::ledger::requests::auth_rule::{AuthRules, Constraint};
use crate::ledger::requests::author_agreement::{AcceptanceMechanisms, GetTxnAuthorAgreementData};
use crate::ledger::requests::cred_def::CredentialDefinition;
use crate::ledger::requests::node::NodeOperationData;
use crate::ledger::requests::pool::Schedule;
use crate::ledger::requests::rev_reg::RevocationRegistryDelta;
use crate::ledger::requests::rev_reg_def::{RegistryType, RevocationRegistryDefinition};
#[cfg(any(feature = "rich_schema", test))]
Expand Down Expand Up @@ -673,6 +674,50 @@ pub extern "C" fn indy_vdr_build_pool_restart_request(
}
}

#[no_mangle]
pub extern "C" fn indy_vdr_build_pool_upgrade_request(
identifier: FfiStr,
name: FfiStr,
version: FfiStr,
action: FfiStr,
sha256: FfiStr,
timeout: i32,
schedule: FfiStr,
justification: FfiStr,
reinstall: i8,
force: i8,
package: FfiStr,
handle_p: *mut RequestHandle,
) -> ErrorCode {
catch_err! {
trace!("Build POOL_UPGRADE request");
check_useful_c_ptr!(handle_p);
let builder = get_request_builder()?;
let identifier = DidValue::from_str(identifier.as_str())?;
let name = name.as_str();
let version = version.as_str();
let action = action.as_str();
let sha256 = sha256.as_str();
let timeout = if timeout == -1 { None } else { Some(timeout as u32) };
let schedule = match schedule.as_opt_str() {
Some(s) => {
let schedule: Schedule = serde_json::from_str(s).with_input_err("Error deserializing Schedule value as JSON")?;
Some(schedule)
}
None => None,
};
let justification = justification.into_opt_string();
let package = package.into_opt_string();
let req = builder.build_pool_upgrade_request(&identifier, name, version, action, sha256, timeout, schedule,
justification.as_deref(), reinstall != 0, force != 0, package.as_deref())?;
let handle = add_request(req)?;
unsafe {
*handle_p = handle;
}
Ok(ErrorCode::Success)
}
}

#[no_mangle]
pub extern "C" fn indy_vdr_build_auth_rule_request(
submitter_did: FfiStr,
Expand Down
4 changes: 4 additions & 0 deletions wrappers/python/demo/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
build_get_auth_rule_request,
build_ledgers_freeze_request,
build_get_frozen_ledgers_request,
build_pool_upgrade_request,
# build_revoc_reg_entry_request,
# build_rich_schema_request,
# build_get_schema_object_by_id_request,
Expand Down Expand Up @@ -186,6 +187,9 @@ async def basic_test(transactions_path):
req = build_get_frozen_ledgers_request(identifier)
log("Get Frozen Ledgers request:", req.body)

req = build_pool_upgrade_request(identifier, 'up', '2.0.0', 'start', 'abc', None, {}, None, False, False, None)
log("Pool Upgrade request:", req.body)

# req = build_rich_schema_request(
# None, "did:sov:some_hash", '{"some": 1}', "test", "version", "sch", "1.0.0"
# )
Expand Down
68 changes: 68 additions & 0 deletions wrappers/python/indy_vdr/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,74 @@ def build_pool_restart_request(
return Request(handle)


def build_pool_upgrade_request(
identifier: str,
name: str,
version: str,
action: str,
sha256: str,
timeout: Optional[int],
schedule: Optional[Union[bytes, str, dict]],
justification: Optional[str],
reinstall: bool,
force: bool,
package: Optional[str]
) -> str:
"""
Builds an POOL_UPGRADE request.
Request to upgrade Pool.
Args:
identifier: Identifier (DID) of the transaction author as base58-encoded
string.
name: Human-readable name for the upgrade.
version: The version of indy-node package we perform upgrade to.
Must be greater than existing one (or equal if reinstall flag is True).
action: Either `start` or `cancel`.
sha256: hash of the package.
timeout: (Optional) Limits upgrade time on each Node.
schedule: (Optional) Schedule of when to perform upgrade on each node. Map Node DIDs to upgrade time.
justification: (Optional) justification string for this particular Upgrade.
reinstall: Whether it's allowed to re-install the same version. False by default.
force: Whether we should apply transaction (schedule Upgrade) without waiting
for consensus of this transaction.
package: (Optional) Package to be upgraded.
"""
handle = RequestHandle()
identifier_p = encode_str(identifier)
name_p = encode_str(name)
version_p = encode_str(version)
action_p = encode_str(action)
sha256_p = encode_str(sha256)
timeout_p = c_int32(timeout) if timeout else c_int32(-1)
schedule_p = (
encode_str(schedule)
if isinstance(schedule, (str, bytes))
else encode_json(schedule)
)
justification_p = encode_str(justification)
c_reinstall = c_int8(reinstall)
c_force = c_int8(force)
package_p = encode_str(package)
do_call(
"indy_vdr_build_pool_upgrade_request",
identifier_p,
name_p,
version_p,
action_p,
sha256_p,
timeout_p,
schedule_p,
justification_p,
c_reinstall,
c_force,
package_p,
byref(handle),
)
return Request(handle)


def build_auth_rule_request(
submitter_did: str,
txn_type: str,
Expand Down

0 comments on commit 01c8dd4

Please sign in to comment.