Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dont return null when stringified null is found in message data on ao.read #319

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/common/contracts/ao-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ export class AOProcess implements AOContract {
this.ao = ao;
}

private isMessageDataEmpty(messageData: string | null | undefined): boolean {
return (
messageData === undefined ||
messageData === 'null' || // This is what the CU returns for 'nil' values that are json.encoded
messageData === '' ||
messageData === null
);
}

async read<K>({
tags,
retries = 3,
Expand Down Expand Up @@ -90,9 +99,9 @@ export class AOProcess implements AOContract {
throw new Error(`${error}${messageData ? `: ${messageData}` : ''}`);
}

// return empty object if no data is returned
if (messageData === undefined) {
return {} as K;
// return undefined if no data is returned
if (this.isMessageDataEmpty(messageData)) {
return undefined as K;
}

const response: K = safeDecode<K>(result.Messages[0].Data);
Expand Down Expand Up @@ -187,7 +196,7 @@ export class AOProcess implements AOContract {
);
}

if (output.Messages[0].Data === undefined) {
if (this.isMessageDataEmpty(output.Messages[0].Data)) {
return { id: messageId };
}

Expand Down
8 changes: 4 additions & 4 deletions src/common/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export class ARIOReadable implements AoARIORead {
}: {
name: string;
}): Promise<AoArNSNameData | undefined> {
return this.process.read<AoArNSNameData>({
return this.process.read<AoArNSNameData | undefined>({
tags: [
{ name: 'Action', value: 'Record' },
{ name: 'Name', value: name },
Expand Down Expand Up @@ -242,7 +242,7 @@ export class ARIOReadable implements AoARIORead {
}: {
name: string;
}): Promise<AoArNSReservedNameData | undefined> {
return this.process.read<AoArNSReservedNameData>({
return this.process.read<AoArNSReservedNameData | undefined>({
tags: [
{ name: 'Action', value: 'Reserved-Name' },
{ name: 'Name', value: name },
Expand Down Expand Up @@ -276,8 +276,8 @@ export class ARIOReadable implements AoARIORead {
}: {
address: WalletAddress;
vaultId: string;
}): Promise<AoVaultData> {
return this.process.read<AoVaultData>({
}): Promise<AoVaultData | undefined> {
return this.process.read<AoVaultData | undefined>({
tags: [
{ name: 'Action', value: 'Vault' },
{ name: 'Address', value: address },
Expand Down
Loading