Skip to content

Commit

Permalink
feat(rust): remove (C) usage of AccountId, add getter for payerAccountId
Browse files Browse the repository at this point in the history
  • Loading branch information
mehcode committed Jun 14, 2022
1 parent fc4ecaa commit 23c0f61
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
6 changes: 6 additions & 0 deletions sdk/rust/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ impl Client {
*self.payer_account_id.write() = Some(id);
}

/// Gets the account that is, by default, paying for transactions and queries built with
/// this client.
pub fn payer_account_id(&self) -> Option<AccountId> {
self.payer_account_id.read().clone()
}

/// Adds a signer that will, by default, sign for all transactions and queries built
/// with this client.
///
Expand Down
31 changes: 29 additions & 2 deletions sdk/rust/src/ffi/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,38 @@ pub extern "C" fn hedera_client_free(client: *mut Client) {
/// Sets the account that will, by default, be paying for transactions and queries built with
/// this client.
#[no_mangle]
pub extern "C" fn hedera_client_set_payer_account_id(client: *mut Client, id: AccountId) {
pub extern "C" fn hedera_client_set_payer_account_id(
client: *mut Client,
id_shard: u64,
id_realm: u64,
id_num: u64,
) {
assert!(!client.is_null());

let client = unsafe { &*client };
client.set_payer_account_id(id);
client.set_payer_account_id(AccountId { shard: id_shard, realm: id_realm, num: id_num });
}

/// Gets the account that is, by default, paying for transactions and queries built with
/// this client.
#[no_mangle]
pub extern "C" fn hedera_client_get_payer_account_id(
client: *mut Client,
id_shard: *mut u64,
id_realm: *mut u64,
id_num: *mut u64,
) {
assert!(!client.is_null());

let client = unsafe { &*client };

if let Some(payer_account_id) = client.payer_account_id() {
unsafe {
*id_shard = payer_account_id.shard;
*id_realm = payer_account_id.realm;
*id_num = payer_account_id.num;
}
}
}

/// Adds a signer that will, by default, sign for all transactions and queries built
Expand Down

0 comments on commit 23c0f61

Please sign in to comment.