Skip to content

Latest commit

 

History

History
274 lines (186 loc) · 5.56 KB

API.md

File metadata and controls

274 lines (186 loc) · 5.56 KB

Public API of the Hub Actor

Table of Contents

Public API

  • getMetadata() : ContractMetadata
  • getTotalMinted() : Nat
  • balanceOf(p : Principal) : [Text]
  • ownerOf(id : Text) : async Result.Result<Principal, Error>
  • isAuthorized(id : Text, p : Principal) : Bool
  • getAuthorized(id : Text) : [Principal]

query getMetadata() : ContractMetadata 

Returns the metadata set by the owner of the hub. Default value: {name = "none"; symbol = "none"}.


query getTotalMinted() : Nat

Returns the total amount of minted NFTs (does not include assets).


balanceOf(p : Principal) : [Text]

Returns the tokens of the given principal.


ownerOf(id : Text) : async Result.Result<Principal, Error>

Returns the owner of the NFT with given identifier.


isAuthorized(id : Text, p : Principal) : Bool

Returns whether the given principal is authorized to change to NFT with the given identifier.


getAuthorized(id : Text) : [Principal]

Returns which principals are authorized to change the NFT with the given identifier.

Sending Cycles

wallet_receive()

| TODO

Private API

  • init(owners : [Principal], metadata : ContractMetadata)
  • updateContractOwners(user : Principal, isAuthorized : Bool) : Result.Result<(), Error>
  • setEventCallback(cb : EventCallback)
  • getContractInfo() : ContractInfo
  • mint(egg : NftEgg) : Result<Text, Error>
  • transfer(transferRequest : TransferRequest) : Result.Result<(), Error>
  • writeStaged(data : WriteNFT) : Result<Text, Error>
  • assetRequest(data : AssetRequest) : Result<(), Error>
  • listAssets() : [(Text, Text, Nat)]
  • tokenByIndex(id : Text) : Result.Result<PublicNft, Error>
  • queryProperties(q : QueryRequest) : Result.Result<Properties, Error>
  • updateProperties(u : UpdateRequest) : Result.Result<Properties, Error>
init(owners : [Principal], metadata : ContractMetadata)

Initializes the hub, and can only be called once. Sets the metadata and appends the given owners to the current contract owner(s).


func updateContractOwners(user : Principal, isAuthorized : Bool) : Result.Result<(), Error>

Updates the access rights of one of the contact owners.


updateEventCallback(update : UpdateEventCallback)

Removes or updates the event callback.


getEventCallbackStatus() : EventCallbackStatus

Returns the event callback status.


mint(egg : NftEgg) : Result<Text, Error>

Mints a new NFT. Assigns the hub as owner if none is given.


transfer(to : Principal, id : Text) : Result.Result<(), Error> 

Transfers one of your own NFTs to another principal.


authorize(req : AuthorizeRequest) : async Result.Result<(), Error>

Allows the caller to authorize another principal to act on its behalf.


writeStaged(data : WriteNFT) : Result<Text, Error>

Writes a part of an NFT to the staged data. NOTE: Initializing another NFT will destruct the data in the buffer.


assetRequest(data : AssetRequest) : Result<(), Error>

Allows you to replace delete and stage NFTs.


getContractInfo() : ContractInfo

Returns the contract info which includes: heap size, memory size, total minted, cycles, etc... (see ContractInfo).


listAssets() : [(Text, Text, Nat)]

List all the static assets.


tokenByIndex(id : Text) : Result.Result<PublicNft, Error>

Gets the token with the given identifier.


tokenChunkByIndex(id : Text, page : Nat) : async ChunkResult

Gets the token chuck with the given identifier and page number.


queryProperties(q : QueryRequest) : Result.Result<Properties, Error>

Returns the attributes of an NFT based on the given query.


updateProperties(u : UpdateRequest) : Result.Result<Properties, Error>

Updates the attributes of an NFT and returns the resulting (updated) attributes.

Http Request

/nft/{id}

Returns the NFT with the given {id}.

{static}

Returns the static asset at the given path.

public query func http_request(request : Http.Request) : async Http.Response
type HeaderField = (Text, Text);

type Request = {
    body    : Blob;
    headers : [HeaderField];
    method  : Text;
    url     : Text;
};

Response = {
    body               : Blob;
    headers            : [HeaderField];
    status_code        : Nat16;
    streaming_strategy : ?StreamingStrategy;
};

Streaming Strategy

Sometimes an NFT needs to be devided into chunk because it is too large. In this case a streaming strategy gets passed in the HTTP reponse.

public type StreamingStrategy = {
    #Callback: {
        token    : StreamingCallbackToken;
        callback : StreamingCallback;
    };
};

In this case a callback is provided with a token and a callback that can be used to retreive the binary data corresponding with that token.

public type StreamingCallback = query (StreamingCallbackToken) -> async (StreamingCallbackResponse);

public type StreamingCallbackToken =  {
    content_encoding : Text;
    index            : Nat;
    key              : Text;
};

public type StreamingCallbackResponse = {
    body  : Blob;
    token : ?StreamingCallbackToken;
};

You can find an example in the examples directory.