diff --git a/src/abi/contract.ts b/src/abi/contract.ts index d4d6236a8..2362914bc 100644 --- a/src/abi/contract.ts +++ b/src/abi/contract.ts @@ -1,4 +1,5 @@ import { ABIMethod, ABIMethodParams, getMethodByName } from './method'; +import { ARC28Event } from './event'; export interface ABIContractNetworkInfo { appID: number; @@ -13,6 +14,7 @@ export interface ABIContractParams { desc?: string; networks?: ABIContractNetworks; methods: ABIMethodParams[]; + events?: ARC28Event[]; } export class ABIContract { @@ -20,6 +22,8 @@ export class ABIContract { public readonly description?: string; public readonly networks: ABIContractNetworks; public readonly methods: ABIMethod[]; + /** [ARC-28](https://arc.algorand.foundation/ARCs/arc-0028) events that MAY be emitted by this contract */ + public readonly events?: ARC28Event[]; constructor(params: ABIContractParams) { if ( @@ -34,6 +38,7 @@ export class ABIContract { this.description = params.desc; this.networks = params.networks ? { ...params.networks } : {}; this.methods = params.methods.map((method) => new ABIMethod(method)); + this.events = params.events; } toJSON(): ABIContractParams { @@ -42,6 +47,7 @@ export class ABIContract { desc: this.description, networks: this.networks, methods: this.methods.map((method) => method.toJSON()), + events: this.events, }; } diff --git a/src/abi/event.ts b/src/abi/event.ts new file mode 100644 index 000000000..0f8652607 --- /dev/null +++ b/src/abi/event.ts @@ -0,0 +1,16 @@ +/** [ARC-28](https://arc.algorand.foundation/ARCs/arc-0028) event description */ +export interface ARC28Event { + /** The name of the event */ + name: string; + /** Optional, user-friendly description for the event */ + desc?: string; + /** The arguments of the event, in order */ + args: Array<{ + /** The type of the argument */ + type: string; + /** Optional, user-friendly name for the argument */ + name?: string; + /** Optional, user-friendly description for the argument */ + desc?: string; + }>; +} diff --git a/src/abi/method.ts b/src/abi/method.ts index 00704efbf..709895a58 100644 --- a/src/abi/method.ts +++ b/src/abi/method.ts @@ -2,6 +2,7 @@ import { genericHash } from '../nacl/naclWrappers'; import { ABIType, ABITupleType } from './abi_type'; import { ABITransactionType, abiTypeIsTransaction } from './transaction'; import { ABIReferenceType, abiTypeIsReference } from './reference'; +import { ARC28Event } from './event'; function parseMethodSignature( signature: string @@ -61,6 +62,10 @@ export interface ABIMethodParams { desc?: string; args: ABIMethodArgParams[]; returns: ABIMethodReturnParams; + /** Optional, is it a read-only method (according to [ARC-22](https://arc.algorand.foundation/ARCs/arc-0022)) */ + readonly?: boolean; + /** [ARC-28](https://arc.algorand.foundation/ARCs/arc-0028) events that MAY be emitted by this method */ + events?: ARC28Event[]; } export type ABIArgumentType = ABIType | ABITransactionType | ABIReferenceType; @@ -77,6 +82,8 @@ export class ABIMethod { }>; public readonly returns: { type: ABIReturnType; description?: string }; + public readonly events?: ARC28Event[]; + public readonly readonly?: boolean; constructor(params: ABIMethodParams) { if ( @@ -111,6 +118,9 @@ export class ABIMethod { : ABIType.from(params.returns.type), description: params.returns.desc, }; + + this.events = params.events; + this.readonly = params.readonly; } getSignature(): string { @@ -147,6 +157,8 @@ export class ABIMethod { type: this.returns.type.toString(), desc: this.returns.description, }, + events: this.events, + readonly: this.readonly, }; }