Skip to content

Commit 5defc43

Browse files
committed
Fix RecordPlaintext.owner() for private records and correct OwnedRecord property names in record-provider
1 parent 84d4205 commit 5defc43

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

sdk/src/record-provider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ class NetworkRecordProvider implements RecordProvider {
262262
const recordsPts = await this.networkClient.findRecords(startHeight, endHeight, searchParameters.unspent, ["credits.aleo"], microcredits, maxAmount, searchParameters.nonces, this.account.privateKey());
263263
return recordsPts.map((record) => ({
264264
owner: record.owner().toString(),
265-
programName: 'credits.aleo',
266-
recordName: 'credits',
267-
recordPlaintext: record.toString(),
265+
program_name: 'credits.aleo',
266+
record_name: 'credits',
267+
record_plaintext: record.toString(),
268268
}));
269269
}
270270

wasm/src/record/record_plaintext.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use crate::{
3232
CurrentNetwork,
3333
FieldNative,
3434
IdentifierNative,
35+
LiteralNative,
3536
PlaintextEntryNative,
3637
PlaintextNative,
3738
ProgramIDNative,
@@ -108,7 +109,10 @@ impl RecordPlaintext {
108109
pub fn owner(&self) -> Result<Address, String> {
109110
match self.0.owner() {
110111
Owner::<CurrentNetwork, PlaintextNative>::Public(owner) => Ok(Address::from(*owner)),
111-
_ => Err("Record is not public".to_string()),
112+
Owner::<CurrentNetwork, PlaintextNative>::Private(plaintext) => match plaintext {
113+
PlaintextNative::Literal(LiteralNative::Address(address), _) => Ok(Address::from(*address)),
114+
_ => Err("Private owner is not an address literal".to_string()),
115+
},
112116
}
113117
}
114118

@@ -469,6 +473,20 @@ mod tests {
469473
assert!(RecordPlaintext::from_string(invalid_bech32).is_err());
470474
}
471475

476+
#[wasm_bindgen_test]
477+
fn test_owner_with_private_visibility() {
478+
let record = RecordPlaintext::from_string(CREDITS_RECORD).unwrap();
479+
let owner = record.owner().unwrap();
480+
assert_eq!(owner.to_string(), "aleo1j7qxyunfldj2lp8hsvy7mw5k8zaqgjfyr72x2gh3x4ewgae8v5gscf5jh3");
481+
}
482+
483+
#[wasm_bindgen_test]
484+
fn test_owner_with_private_visibility_battleship() {
485+
let record = RecordPlaintext::from_string(BATTLESHIP_RECORD).unwrap();
486+
let owner = record.owner().unwrap();
487+
assert_eq!(owner.to_string(), "aleo1kh5t7m30djl0ecdn4f5vuzp7dx0tcwh7ncquqjkm4matj2p2zqpqm6at48");
488+
}
489+
472490
#[wasm_bindgen_test]
473491
fn test_record_decrypt_record_sender_ciphertext() {
474492
// Get the private key corresponding to the record.

0 commit comments

Comments
 (0)