diff --git a/packages/near-contract-standards/lib/fungible_token/events.d.ts b/packages/near-contract-standards/lib/fungible_token/events.d.ts index 840b2aad0..b3c3377db 100644 --- a/packages/near-contract-standards/lib/fungible_token/events.d.ts +++ b/packages/near-contract-standards/lib/fungible_token/events.d.ts @@ -19,8 +19,10 @@ import { Option } from "../non_fungible_token/utils"; import { AccountId, Balance } from "near-sdk-js"; export declare type Nep141EventKind = FtMint[] | FtTransfer[] | FtBurn[]; export declare class Nep141Event extends NearEvent { + standard: string; version: string; - event_kind: Nep141EventKind; + event: string; + data: Nep141EventKind; constructor(version: string, event_kind: Nep141EventKind); } /** Data to log for an FT mint event. To log this event, call [`.emit()`](FtMint::emit). */ diff --git a/packages/near-contract-standards/lib/fungible_token/events.js b/packages/near-contract-standards/lib/fungible_token/events.js index 512f72c95..1fd1599bd 100644 --- a/packages/near-contract-standards/lib/fungible_token/events.js +++ b/packages/near-contract-standards/lib/fungible_token/events.js @@ -15,11 +15,14 @@ * or [`FtBurn::emit_many`] respectively. */ import { NearEvent } from "../event"; +import { toSnakeCase } from "../util"; export class Nep141Event extends NearEvent { constructor(version, event_kind) { super(); + this.standard = "nep141"; this.version = version; - this.event_kind = event_kind; + this.event = toSnakeCase(event_kind[0].constructor.name); + this.data = event_kind; } } /** Data to log for an FT mint event. To log this event, call [`.emit()`](FtMint::emit). */ diff --git a/packages/near-contract-standards/lib/non_fungible_token/events.d.ts b/packages/near-contract-standards/lib/non_fungible_token/events.d.ts index 59f8b49e2..a93af09ec 100644 --- a/packages/near-contract-standards/lib/non_fungible_token/events.d.ts +++ b/packages/near-contract-standards/lib/non_fungible_token/events.d.ts @@ -16,10 +16,12 @@ import { AccountId } from "near-sdk-js"; import { NearEvent } from "../event"; import { TokenId } from "./token"; -export declare type Nep171EventKind = NftMint[] | NftTransfer[] | NftBurn[]; +export declare type Nep171EventKind = NftMint[] | NftTransfer[] | NftBurn[] | NftContractMetadataUpdate[]; export declare class Nep171Event extends NearEvent { + standard: string; version: string; - event_kind: Nep171EventKind; + event: string; + data: Nep171EventKind; constructor(version: string, event_kind: Nep171EventKind); } /** Data to log for an NFT mint event. To log this event, call `.emit()` */ @@ -65,3 +67,14 @@ export declare class NftBurn { * where each [`NftBurn`] represents the data of each burn. */ static emit_many(data: NftBurn[]): void; } +/** Data to log for an NFT contract metadata updates. To log this event, call [`.emit()`](NftContractMetadataUpdate.emit). */ +export declare class NftContractMetadataUpdate { + memo?: string; + constructor(memo?: string); + /** Logs the event to the host. This is required to ensure that the event is triggered + * and to consume the event. */ + emit(): void; + /** Emits an contract metadata update event, through `near.log`, + * where each [`NftBurn`] represents the data of each burn. */ + static emit_many(data: NftContractMetadataUpdate[]): void; +} diff --git a/packages/near-contract-standards/lib/non_fungible_token/events.js b/packages/near-contract-standards/lib/non_fungible_token/events.js index 69622fd56..36142bdcb 100644 --- a/packages/near-contract-standards/lib/non_fungible_token/events.js +++ b/packages/near-contract-standards/lib/non_fungible_token/events.js @@ -1,9 +1,12 @@ import { NearEvent } from "../event"; +import { toSnakeCase } from "../util"; export class Nep171Event extends NearEvent { constructor(version, event_kind) { super(); + this.standard = "nep171"; this.version = version; - this.event_kind = event_kind; + this.event = toSnakeCase(event_kind[0].constructor.name); + this.data = event_kind; } } /** Data to log for an NFT mint event. To log this event, call `.emit()` */ @@ -64,6 +67,22 @@ export class NftBurn { new_171_v1(data).emit(); } } +/** Data to log for an NFT contract metadata updates. To log this event, call [`.emit()`](NftContractMetadataUpdate.emit). */ +export class NftContractMetadataUpdate { + constructor(memo) { + this.memo = memo; + } + /** Logs the event to the host. This is required to ensure that the event is triggered + * and to consume the event. */ + emit() { + NftContractMetadataUpdate.emit_many([this]); + } + /** Emits an contract metadata update event, through `near.log`, + * where each [`NftBurn`] represents the data of each burn. */ + static emit_many(data) { + new_171_v1(data).emit(); + } +} function new_171(version, event_kind) { return new Nep171Event(version, event_kind); } diff --git a/packages/near-contract-standards/lib/util.d.ts b/packages/near-contract-standards/lib/util.d.ts new file mode 100644 index 000000000..44a75fe1d --- /dev/null +++ b/packages/near-contract-standards/lib/util.d.ts @@ -0,0 +1 @@ +export declare const toSnakeCase: (str: string) => string; diff --git a/packages/near-contract-standards/lib/util.js b/packages/near-contract-standards/lib/util.js new file mode 100644 index 000000000..4f8afc021 --- /dev/null +++ b/packages/near-contract-standards/lib/util.js @@ -0,0 +1,3 @@ +export const toSnakeCase = (str) => { + return str.replace(/[A-Z]/g, (letter, index) => { return index == 0 ? letter.toLowerCase() : '_' + letter.toLowerCase(); }); +}; diff --git a/packages/near-contract-standards/src/fungible_token/events.ts b/packages/near-contract-standards/src/fungible_token/events.ts index 96a613c07..862d0ecbf 100644 --- a/packages/near-contract-standards/src/fungible_token/events.ts +++ b/packages/near-contract-standards/src/fungible_token/events.ts @@ -18,19 +18,24 @@ import { NearEvent } from "../event"; import { Option } from "../non_fungible_token/utils"; import { AccountId, Balance } from "near-sdk-js"; +import { toSnakeCase } from "../util"; export type Nep141EventKind = FtMint[] | FtTransfer[] | FtBurn[]; export class Nep141Event extends NearEvent { - version: string; - event_kind: Nep141EventKind; - - constructor(version: string, event_kind: Nep141EventKind) { - super(); - this.version = version; - this.event_kind = event_kind; - } + standard: string; + version: string; + event: string; + data: Nep141EventKind; + + constructor(version: string, event_kind: Nep141EventKind) { + super(); + this.standard = "nep141" + this.version = version + this.event = toSnakeCase(event_kind[0].constructor.name) + this.data = event_kind } +} /** Data to log for an FT mint event. To log this event, call [`.emit()`](FtMint::emit). */ export class FtMint { diff --git a/packages/near-contract-standards/src/non_fungible_token/events.ts b/packages/near-contract-standards/src/non_fungible_token/events.ts index f8d5e8109..2d0863f39 100644 --- a/packages/near-contract-standards/src/non_fungible_token/events.ts +++ b/packages/near-contract-standards/src/non_fungible_token/events.ts @@ -16,17 +16,22 @@ import { AccountId } from "near-sdk-js"; import { NearEvent } from "../event"; import { TokenId } from "./token"; +import { toSnakeCase } from "../util"; -export type Nep171EventKind = NftMint[] | NftTransfer[] | NftBurn[]; +export type Nep171EventKind = NftMint[] | NftTransfer[] | NftBurn[] | NftContractMetadataUpdate[]; export class Nep171Event extends NearEvent { + standard: string; version: string; - event_kind: Nep171EventKind; + event: string; + data: Nep171EventKind; constructor(version: string, event_kind: Nep171EventKind) { super(); - this.version = version; - this.event_kind = event_kind; + this.standard = "nep171" + this.version = version + this.event = toSnakeCase(event_kind[0].constructor.name) + this.data = event_kind } } @@ -97,6 +102,25 @@ export class NftBurn { } } +/** Data to log for an NFT contract metadata updates. To log this event, call [`.emit()`](NftContractMetadataUpdate.emit). */ +export class NftContractMetadataUpdate { + constructor( + public memo?: string + ) {} + + /** Logs the event to the host. This is required to ensure that the event is triggered + * and to consume the event. */ + emit() { + NftContractMetadataUpdate.emit_many([this]); + } + + /** Emits an contract metadata update event, through `near.log`, + * where each [`NftBurn`] represents the data of each burn. */ + static emit_many(data: NftContractMetadataUpdate[]) { + new_171_v1(data).emit(); + } +} + function new_171(version: string, event_kind: Nep171EventKind): NearEvent { return new Nep171Event(version, event_kind); } diff --git a/packages/near-contract-standards/src/util.ts b/packages/near-contract-standards/src/util.ts new file mode 100644 index 000000000..6878f2d95 --- /dev/null +++ b/packages/near-contract-standards/src/util.ts @@ -0,0 +1,3 @@ +export const toSnakeCase = (str: string) => { + return str.replace(/[A-Z]/g, (letter, index) => { return index == 0 ? letter.toLowerCase() : '_'+ letter.toLowerCase();}); +} \ No newline at end of file