美文网首页
第三课作业 motoko源码

第三课作业 motoko源码

作者: Limit_ | 来源:发表于2022-01-10 03:05 被阅读0次
import Nat "mo:base/Nat";
import Text "mo:base/Text";
actor Counter {
  public type Key = Text;
  public type Path = Text;
  public type Chunk_Id = Nat;
  public type SetAssetContentArguments = {
    key: Key;
    sha256:?[Nat8];
    chunk_ids: [Chunk_Id];
    content_encoding: Text;
  };
  public type StreamingCallbackHttpResponse = {
      token: ?StreamingCallbackToken;
      body: Blob;
  };
  public type StreamingCallbackToken = {
      key: Text;
      sha256: ?[Nat8];
      index:Nat;
      content_encoding: Text;
  };
  public type StreamingStrategy = {
      #Callback : {
          token: StreamingCallbackToken;
          Callback: shared query StreamingCallbackToken -> async StreamingCallbackHttpResponse;
      };
  };
  public type HeaderField = (Text, Text);
  public type HttpRequest =  {
      url: Text;
      method: Text;
      body: Blob;
      headers: [HeaderField];
  };
  public type HttpResponse = {
      body: Blob;
      headers: [HeaderField];
      streaming_strategy: ?StreamingStrategy;
      status_code: Nat16;
  };
  
  public shared query func http_request(request: HttpRequest) : async HttpResponse {
      {
        body = Text.encodeUtf8("<html><body><h2>the counter is: " # Nat.toText(counter) # "</h2><body></html>");
        headers = [];
        streaming_strategy = null;
        status_code= 200;
      }
  };

 stable var counter = 0;

  // Get the value of the counter.
  public query func get() : async Nat {
    return counter;
  };

  // Set the value of the counter.
  public func set(n : Nat) : async () {
    counter := n;
  };

  // Increment the value of the counter.
  public func inc() : async () {
    counter += 1;
  };


  
};


相关文章

网友评论

      本文标题:第三课作业 motoko源码

      本文链接:https://www.haomeiwen.com/subject/bxzpcrtx.html