Skip to content

Commit

Permalink
Merge pull request #384 from fospring/nujabes403develop
Browse files Browse the repository at this point in the history
Nujabes403develop
  • Loading branch information
ailisp authored Mar 18, 2024
2 parents 61fe54e + 8c038f1 commit 2fb8105
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 17 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/near-contract-standards/lib/util.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/near-contract-standards/lib/util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 13 additions & 8 deletions packages/near-contract-standards/src/fungible_token/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
32 changes: 28 additions & 4 deletions packages/near-contract-standards/src/non_fungible_token/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/near-contract-standards/src/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const toSnakeCase = (str: string) => {
return str.replace(/[A-Z]/g, (letter, index) => { return index == 0 ? letter.toLowerCase() : '_'+ letter.toLowerCase();});
}

0 comments on commit 2fb8105

Please sign in to comment.