From 7a7802aa53e984658907ed94c53e6eb0439e7b5c Mon Sep 17 00:00:00 2001 From: Quint Daenen Date: Sun, 22 Oct 2023 14:06:34 +0200 Subject: [PATCH] Add JSON examples. --- .gitignore | 1 + Makefile | 3 + README.md | 26 ++- agent.go | 95 +++------ agent_test.go | 53 +++-- candid/internal/gen.go | 2 - cmd/README.md | 20 -- cmd/goic/README.md | 40 ++++ cmd/{ => goic}/internal/cmd/cmd.go | 0 cmd/{ => goic}/internal/cmd/cmd_test.go | 0 cmd/{ => goic}/main.go | 16 +- gen/generator.go | 269 ++++++++++++++++++++++++ gen/templates/actor_mo.gotmpl | 12 ++ gen/templates/agent.gotmpl | 6 +- gen/templates/agent_test.gotmpl | 2 +- gen/templates/types_mo.gotmpl | 6 + ic/assetstorage/actor.mo | 106 ++++++++++ ic/assetstorage/agent.go | 198 +++-------------- ic/assetstorage/agent_test.go | 2 +- ic/assetstorage/types.mo | 29 +++ ic/cmc/actor.mo | 19 ++ ic/cmc/agent.go | 24 +-- ic/cmc/agent_test.go | 2 +- ic/cmc/types.mo | 16 ++ ic/dfx.json | 8 + ic/ic_test.go | 85 ++++++++ ic/icparchive/actor.mo | 10 + ic/icparchive/agent.go | 6 +- ic/icparchive/agent_test.go | 2 +- ic/icparchive/types.mo | 15 ++ ic/icpledger/actor.mo | 31 +++ ic/icpledger/agent.go | 48 +---- ic/icpledger/agent_test.go | 2 +- ic/icpledger/types.mo | 26 +++ ic/icrc1/actor.mo | 37 ++++ ic/icrc1/agent.go | 60 +----- ic/icrc1/agent_test.go | 2 +- ic/icrc1/types.mo | 10 + ic/testdata/gen.go | 17 ++ ic/types_agent_test.go | 48 +---- ic/wallet/actor.mo | 106 ++++++++++ ic/wallet/agent.go | 198 +++-------------- ic/wallet/agent_test.go | 2 +- ic/wallet/types.mo | 29 +++ principal/accountid.go | 36 ++-- principal/icrc/account_test.go | 32 +-- 46 files changed, 1108 insertions(+), 649 deletions(-) delete mode 100644 cmd/README.md create mode 100644 cmd/goic/README.md rename cmd/{ => goic}/internal/cmd/cmd.go (100%) rename cmd/{ => goic}/internal/cmd/cmd_test.go (100%) rename cmd/{ => goic}/main.go (90%) create mode 100644 gen/templates/actor_mo.gotmpl create mode 100644 gen/templates/types_mo.gotmpl create mode 100755 ic/assetstorage/actor.mo create mode 100755 ic/assetstorage/types.mo create mode 100755 ic/cmc/actor.mo create mode 100755 ic/cmc/types.mo create mode 100644 ic/dfx.json create mode 100644 ic/ic_test.go create mode 100755 ic/icparchive/actor.mo create mode 100755 ic/icparchive/types.mo create mode 100755 ic/icpledger/actor.mo create mode 100755 ic/icpledger/types.mo create mode 100755 ic/icrc1/actor.mo create mode 100755 ic/icrc1/types.mo create mode 100755 ic/wallet/actor.mo create mode 100755 ic/wallet/types.mo diff --git a/.gitignore b/.gitignore index 2d83068..3c16700 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ coverage.out +ic/.dfx diff --git a/Makefile b/Makefile index 266c61b..f5ce2c6 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,9 @@ test: go test -v -cover ./... +check-moc: + find ic -type f -name '*.mo' -print0 | xargs -0 $(shell dfx cache show)/moc --check + test-cover: go test -v -coverprofile=coverage.out ./... go tool cover -html=coverage.out diff --git a/README.md b/README.md index 1edbd58..1d5edcf 100644 --- a/README.md +++ b/README.md @@ -3,14 +3,6 @@ [![Go Version](https://img.shields.io/github/go-mod/go-version/aviate-labs/agent-go.svg)](https://github.com/aviate-labs/agent-go) [![GoDoc Reference](https://img.shields.io/badge/godoc-reference-blue.svg)](https://pkg.go.dev/github.com/aviate-labs/agent-go) -## Testing - -There are two types of tests within this repository; the normal go tests and [DFX](https://github.com/dfinity/sdk) dependent tests. The test suite will run a local replica through DFX to run some e2e tests. If you do not have it installed then those tests will be ignored. - -```shell -go test -v ./... -``` - ## Packages | Package Name | Links | Description | @@ -24,3 +16,21 @@ go test -v ./... | `principal` | [![DOC](https://img.shields.io/badge/-DOC-blue)](https://pkg.go.dev/github.com/aviate-labs/agent-go/principal) | Generic Identifiers for the Internet Computer | More dependencies in the [go.mod](./go.mod) file. + +## CLI + +```shell +go install github.com/aviate-labs/agent-go/cmd/goic@latest +``` + +Read more [here](cmd/goic/README.md) + +## Testing + +There are two types of tests within this repository; the normal go tests and [DFX](https://github.com/dfinity/sdk) +dependent tests. The test suite will run a local replica through DFX to run some e2e tests. If you do not have it +installed then those tests will be ignored. + +```shell +go test -v ./... +``` diff --git a/agent.go b/agent.go index 9eabec9..26f3b55 100644 --- a/agent.go +++ b/agent.go @@ -7,7 +7,6 @@ import ( "net/url" "time" - "github.com/aviate-labs/agent-go/candid" "github.com/aviate-labs/agent-go/candid/idl" "github.com/aviate-labs/agent-go/certificate" "github.com/aviate-labs/agent-go/identity" @@ -78,56 +77,34 @@ func New(cfg Config) (*Agent, error) { } // Call calls a method on a canister and unmarshals the result into the given values. -func (a Agent) Call(canisterID principal.Principal, methodName string, args []byte, values []any) error { - if len(args) == 0 { - // Default to the empty Candid argument list. - args = []byte{'D', 'I', 'D', 'L', 0, 0} - } - raw, err := a.CallRaw(canisterID, methodName, args) +func (a Agent) Call(canisterID principal.Principal, methodName string, args []any, values []any) error { + rawArgs, err := idl.Marshal(args) if err != nil { return err } - return idl.Unmarshal(raw, values) -} - -// CallCandid calls a method on a canister and returns the raw Candid result as a list of types and values. -func (a Agent) CallCandid(canisterID principal.Principal, methodName string, args []byte) ([]idl.Type, []interface{}, error) { - raw, err := a.CallRaw(canisterID, methodName, args) - if err != nil { - return nil, nil, err + if len(args) == 0 { + // Default to the empty Candid argument list. + rawArgs = []byte{'D', 'I', 'D', 'L', 0, 0} } - return idl.Decode(raw) -} - -// CallRaw calls a method on a canister and returns the raw Candid result. -func (a Agent) CallRaw(canisterID principal.Principal, methodName string, args []byte) ([]byte, error) { requestID, data, err := a.sign(Request{ Type: RequestTypeCall, Sender: a.Sender(), CanisterID: canisterID, MethodName: methodName, - Arguments: args, + Arguments: rawArgs, IngressExpiry: a.expiryDate(), }) if err != nil { - return nil, err + return err } if _, err := a.call(canisterID, data); err != nil { - return nil, err - } - return a.poll(canisterID, *requestID, time.Second, time.Second*10) -} - -// CallString calls a method on a canister and returns the result as a string. -func (a Agent) CallString(canisterID principal.Principal, methodName string, args []byte) (string, error) { - if len(args) == 0 { - args = []byte{'D', 'I', 'D', 'L', 0, 0} + return err } - types, values, err := a.CallCandid(canisterID, methodName, args) + raw, err := a.poll(canisterID, *requestID, time.Second, time.Second*10) if err != nil { - return "", err + return err } - return candid.DecodeValuesString(types, values) + return idl.Unmarshal(raw, values) } // GetCanisterControllers returns the list of principals that can control the given canister. @@ -170,64 +147,40 @@ func (a Agent) GetCanisterModuleHash(canisterID principal.Principal) ([]byte, er return a.GetCanisterInfo(canisterID, "module_hash") } -// Query queries a method on a canister and unmarshals the result into the given values. -func (a Agent) Query(canisterID principal.Principal, methodName string, args []byte, values []any) error { - if len(args) == 0 { - args = []byte{'D', 'I', 'D', 'L', 0, 0} - } - raw, err := a.QueryRaw(canisterID, methodName, args) +func (a Agent) Query(canisterID principal.Principal, methodName string, args []any, values []any) error { + rawArgs, err := idl.Marshal(args) if err != nil { return err } - return idl.Unmarshal(raw, values) -} - -// QueryCandid queries a method on a canister and returns the raw Candid result as a list of types and values. -func (a Agent) QueryCandid(canisterID principal.Principal, methodName string, args []byte) ([]idl.Type, []interface{}, error) { - raw, err := a.QueryRaw(canisterID, methodName, args) - if err != nil { - return nil, nil, err + if len(args) == 0 { + // Default to the empty Candid argument list. + rawArgs = []byte{'D', 'I', 'D', 'L', 0, 0} } - return idl.Decode(raw) -} - -// QueryRaw queries a method on a canister and returns the raw Candid result. -func (a Agent) QueryRaw(canisterID principal.Principal, methodName string, args []byte) ([]byte, error) { _, data, err := a.sign(Request{ Type: RequestTypeQuery, Sender: a.Sender(), CanisterID: canisterID, MethodName: methodName, - Arguments: args, + Arguments: rawArgs, IngressExpiry: a.expiryDate(), }) if err != nil { - return nil, err + return err } resp, err := a.query(canisterID, data) if err != nil { - return nil, err + return err } + var raw []byte switch resp.Status { case "replied": - return resp.Reply["arg"], nil + raw = resp.Reply["arg"] case "rejected": - return nil, fmt.Errorf("(%d) %s", resp.RejectCode, resp.RejectMsg) + return fmt.Errorf("(%d) %s", resp.RejectCode, resp.RejectMsg) default: panic("unreachable") } -} - -// QueryString queries a method on a canister and returns the result as a string. -func (a Agent) QueryString(canisterID principal.Principal, methodName string, args []byte) (string, error) { - if len(args) == 0 { - args = []byte{'D', 'I', 'D', 'L', 0, 0} - } - types, values, err := a.QueryCandid(canisterID, methodName, args) - if err != nil { - return "", err - } - return candid.DecodeValuesString(types, values) + return idl.Unmarshal(raw, values) } // RequestStatus returns the status of the request with the given ID. @@ -237,7 +190,7 @@ func (a Agent) RequestStatus(canisterID principal.Principal, requestID RequestID if err != nil { return nil, nil, err } - var state map[string]interface{} + var state map[string]any if err := cbor.Unmarshal(c, &state); err != nil { return nil, nil, err } diff --git a/agent_test.go b/agent_test.go index ddc5b59..dd954e9 100644 --- a/agent_test.go +++ b/agent_test.go @@ -3,9 +3,10 @@ package agent_test import ( "crypto/ed25519" "crypto/rand" + "encoding/json" "fmt" "github.com/aviate-labs/agent-go" - "github.com/aviate-labs/agent-go/candid" + "github.com/aviate-labs/agent-go/ic" "github.com/aviate-labs/agent-go/identity" "github.com/aviate-labs/agent-go/principal" ) @@ -13,27 +14,51 @@ import ( func Example_anonymous_query() { ledgerID, _ := principal.Decode("ryjl3-tyaaa-aaaaa-aaaba-cai") a, _ := agent.New(agent.Config{}) - args, err := candid.EncodeValueString("record { account = \"9523dc824aa062dcd9c91b98f4594ff9c6af661ac96747daef2090b7fe87037d\" }") - if err != nil { - fmt.Println(err) + var balance struct { + E8S uint64 `ic:"e8s"` } - fmt.Println(a.QueryString(ledgerID, "account_balance_dfx", args)) + _ = a.Query(ledgerID, "account_balance_dfx", []any{map[string]any{ + "account": "9523dc824aa062dcd9c91b98f4594ff9c6af661ac96747daef2090b7fe87037d", + }}, []any{&balance}) + fmt.Println(balance.E8S) // Output: - // (record { 5035232 = 0 : nat64 }) + // 0 +} + +func Example_json() { + raw := `{"e8s":1}` + var balance struct { + // Tags can be combined with json tags. + E8S uint64 `ic:"e8s" json:"e8s"` + } + _ = json.Unmarshal([]byte(raw), &balance) + fmt.Println(balance.E8S) + + a, _ := agent.New(agent.Config{}) + _ = a.Query(ic.LEDGER_PRINCIPAL, "account_balance_dfx", []any{struct { + Account string `json:"account"` + }{ + Account: "9523dc824aa062dcd9c91b98f4594ff9c6af661ac96747daef2090b7fe87037d", + }}, []any{&balance}) // Repurposing the balance struct. + rawJSON, _ := json.Marshal(balance) + fmt.Println(string(rawJSON)) + // Output: + // 1 + // {"e8s":0} } func Example_query() { publicKey, privateKey, _ := ed25519.GenerateKey(rand.Reader) id, _ := identity.NewEd25519Identity(publicKey, privateKey) ledgerID, _ := principal.Decode("ryjl3-tyaaa-aaaaa-aaaba-cai") - a, _ := agent.New(agent.Config{ - Identity: id, - }) - args, err := candid.EncodeValueString("record { account = \"9523dc824aa062dcd9c91b98f4594ff9c6af661ac96747daef2090b7fe87037d\" }") - if err != nil { - fmt.Println(err) + a, _ := agent.New(agent.Config{Identity: id}) + var balance struct { + E8S uint64 `ic:"e8s"` } - fmt.Println(a.QueryString(ledgerID, "account_balance_dfx", args)) + _ = a.Query(ledgerID, "account_balance_dfx", []any{map[string]any{ + "account": "9523dc824aa062dcd9c91b98f4594ff9c6af661ac96747daef2090b7fe87037d", + }}, []any{&balance}) + fmt.Println(balance.E8S) // Output: - // (record { 5035232 = 0 : nat64 }) + // 0 } diff --git a/candid/internal/gen.go b/candid/internal/gen.go index c72f844..44242a6 100644 --- a/candid/internal/gen.go +++ b/candid/internal/gen.go @@ -6,8 +6,6 @@ import ( "fmt" "io/ioutil" "log" - - "github.com/pegn/pegn-go" ) func main() { diff --git a/cmd/README.md b/cmd/README.md deleted file mode 100644 index d1b87b9..0000000 --- a/cmd/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Agent CLI - -``` -go install github.com/aviate-labs/agent-go/cmd -cmd --help -> ERROR: command "--help" not found -``` - -```shell -go run main.go fetch ryjl3-tyaaa-aaaaa-aaaba-cai --output=ledger.did -go run main.go generate did ledger.did ledger --output=ledger.go --packageName=main -go fmt ledger.go -``` - -**OR** - -```shell -go run main.go generate remote ryjl3-tyaaa-aaaaa-aaaba-cai ledger --output=ledger.go --packageName=main -go fmt ledger.go -``` diff --git a/cmd/goic/README.md b/cmd/goic/README.md new file mode 100644 index 0000000..4f085e8 --- /dev/null +++ b/cmd/goic/README.md @@ -0,0 +1,40 @@ +# Agent CLI + +``` +go install github.com/aviate-labs/agent-go/cmd/goic +goic version +# 0.0.1 +``` + +## Generating Agents + +To generate an agent you will need the `.did` file. Some interface specifications can be fetched directly from a +canister through the `__get_candid_interface_tmp_hack` endpoint (this gets exposed by default w/ Motoko). Based on this +file an agent can be generated. + +### Options + +The `generate` command can be customized by defining a custom `output` or `packageName` flag. + +### Fetch The DID + +```shell +goic generate did {PATH_TO_DID} {NAME} +``` + +```shell +goic fetch ryjl3-tyaaa-aaaaa-aaaba-cai --output=ledger.did +goic generate did ledger.did ledger --output=ledger.go --packageName=main +go fmt ledger.go +``` + +**OR** + +```shell +goic generate remote {CANISTER_ID} {NAME} +``` + +```shell +goic generate remote ryjl3-tyaaa-aaaaa-aaaba-cai ledger --output=ledger.go --packageName=main +go fmt ledger.go +``` diff --git a/cmd/internal/cmd/cmd.go b/cmd/goic/internal/cmd/cmd.go similarity index 100% rename from cmd/internal/cmd/cmd.go rename to cmd/goic/internal/cmd/cmd.go diff --git a/cmd/internal/cmd/cmd_test.go b/cmd/goic/internal/cmd/cmd_test.go similarity index 100% rename from cmd/internal/cmd/cmd_test.go rename to cmd/goic/internal/cmd/cmd_test.go diff --git a/cmd/main.go b/cmd/goic/main.go similarity index 90% rename from cmd/main.go rename to cmd/goic/main.go index 31797ef..b18ac59 100644 --- a/cmd/main.go +++ b/cmd/goic/main.go @@ -3,15 +3,25 @@ package main import ( "fmt" "github.com/aviate-labs/agent-go" - "github.com/aviate-labs/agent-go/cmd/internal/cmd" + "github.com/aviate-labs/agent-go/cmd/goic/internal/cmd" "github.com/aviate-labs/agent-go/gen" "github.com/aviate-labs/agent-go/principal" "os" ) var root = cmd.NewCommandFork( - "agent-go", - "agent-go is a CLI tool for creating a Go agent.", + "goic", + "`goic` is a CLI tool for creating a Go agent.", + cmd.NewCommand( + "version", + "Print the version of `goic`.", + []string{}, + []cmd.CommandOption{}, + func(args []string, options map[string]string) error { + fmt.Println("0.0.1") + return nil + }, + ), cmd.NewCommand( "fetch", "Fetch a DID from a canister ID.", diff --git a/gen/generator.go b/gen/generator.go index 55e9234..418ccd9 100644 --- a/gen/generator.go +++ b/gen/generator.go @@ -6,8 +6,10 @@ import ( "fmt" "github.com/aviate-labs/agent-go/candid" "github.com/aviate-labs/agent-go/candid/did" + "github.com/aviate-labs/agent-go/candid/idl" "io" "io/fs" + "math/rand" "strings" "text/template" ) @@ -159,6 +161,92 @@ func (g *Generator) Generate() ([]byte, error) { return io.ReadAll(&tmpl) } +func (g *Generator) GenerateActor() ([]byte, error) { + definitions := make(map[string]did.Data) + for _, definition := range g.ServiceDescription.Definitions { + switch definition := definition.(type) { + case did.Type: + definitions[definition.Id] = definition.Data + } + } + + var methods []actorArgsMethod + for _, service := range g.ServiceDescription.Services { + for _, method := range service.Methods { + name := rawName(method.Name) + f := method.Func + + var argumentTypes []agentArgsMethodArgument + for i, t := range f.ArgTypes { + argumentTypes = append(argumentTypes, agentArgsMethodArgument{ + Name: fmt.Sprintf("arg%d", i), + Type: g.dataToMotokoString(t.Data), + }) + } + + var returnTypes []string + for _, t := range f.ResTypes { + returnTypes = append(returnTypes, g.dataToMotokoString(t.Data)) + } + + r := rand.NewSource(idl.Hash(g.CanisterName).Int64()) + var returnValues []string + for _, t := range f.ResTypes { + returnValues = append(returnValues, g.dataToMotokoReturnValue(r, definitions, t.Data)) + } + + typ := "shared" + if f.Annotation != nil && *f.Annotation == did.AnnQuery { + typ = "query" + } + + methods = append(methods, actorArgsMethod{ + Name: name, + Type: typ, + ArgumentTypes: argumentTypes, + ReturnTypes: returnTypes, + ReturnValues: returnValues, + }) + } + } + t, ok := templates["actor_mo"] + if !ok { + return nil, fmt.Errorf("template not found") + } + var tmpl bytes.Buffer + if err := t.Execute(&tmpl, actorArgs{ + CanisterName: g.CanisterName, + Methods: methods, + }); err != nil { + return nil, err + } + return io.ReadAll(&tmpl) +} + +func (g *Generator) GenerateActorTypes() ([]byte, error) { + var definitions []agentArgsDefinition + for _, definition := range g.ServiceDescription.Definitions { + switch definition := definition.(type) { + case did.Type: + definitions = append(definitions, agentArgsDefinition{ + Name: funcName("", definition.Id), + Type: g.dataToMotokoString(definition.Data), + }) + } + } + t, ok := templates["types_mo"] + if !ok { + return nil, fmt.Errorf("template not found") + } + var tmpl bytes.Buffer + if err := t.Execute(&tmpl, actorTypesArgs{ + Definitions: definitions, + }); err != nil { + return nil, err + } + return io.ReadAll(&tmpl) +} + func (g *Generator) GenerateMock() ([]byte, error) { var methods []agentArgsMethod for _, service := range g.ServiceDescription.Services { @@ -217,6 +305,170 @@ func (g *Generator) GenerateMock() ([]byte, error) { return io.ReadAll(&tmpl) } +func (g *Generator) dataToMotokoReturnValue(s rand.Source, definitions map[string]did.Data, data did.Data) string { + r := rand.New(s) + switch t := data.(type) { + case did.DataId: + return g.dataToMotokoReturnValue(s, definitions, definitions[string(t)]) + case did.Blob: + var b [32]byte + r.Read(b[:]) + return fmt.Sprintf("\"x%02X\"", b) + case did.Func: + return "{ /* func */ }" + case did.Principal: + var b [32]byte + r.Read(b[:]) + return fmt.Sprintf("principalOfBlob(\"x%02X\")", b[:]) + case did.Primitive: + switch t { + case "null": + return "()" + case "bool": + return fmt.Sprintf("%t", r.Int()%2 == 0) + case "nat", "int": + return fmt.Sprintf("%d", r.Uint64()) + case "nat8": + return fmt.Sprintf("%d", r.Uint64()%0xFF) + case "nat16": + return fmt.Sprintf("%d", r.Uint64()%0xFFFF) + case "nat32": + return fmt.Sprintf("%d", r.Uint64()%0xFFFFFFFF) + case "nat64": + return fmt.Sprintf("%d", r.Uint64()%0xFFFFFFFFFFFFFFFF) + case "text": + return fmt.Sprintf("\"%d\"", r.Uint64()) + } + case did.Vector: + n := r.Int() % 10 + var values []string + for i := 0; i < n; i++ { + values = append(values, g.dataToMotokoReturnValue(s, definitions, t.Data)) + } + return fmt.Sprintf("[ %s ]", strings.Join(values, ", ")) + case did.Record: + var tuple bool + var fields []string + for _, v := range t { + if v.Name != nil { + var data string + if v.NameData != nil { + data = g.dataToMotokoReturnValue(s, definitions, definitions[*v.NameData]) + } else { + data = g.dataToMotokoReturnValue(s, definitions, *v.Data) + } + fields = append(fields, fmt.Sprintf("%s = %s", *v.Name, data)) + } else { + tuple = true + break + } + } + if !tuple { + return fmt.Sprintf("{ %s }", strings.Join(fields, "; ")) + } + + var values []string + for _, field := range t { + if field.Data != nil { + values = append(values, g.dataToMotokoReturnValue(s, definitions, *field.Data)) + } else { + values = append(values, g.dataToMotokoReturnValue(s, definitions, definitions[*field.NameData])) + } + } + return fmt.Sprintf("( %s )", strings.Join(values, ", ")) + case did.Variant: + r := s.Int63() % int64(len(t)) + field := t[r] + if field.Data != nil { + return fmt.Sprintf("#%s(%s)", *field.Name, g.dataToMotokoReturnValue(s, definitions, *field.Data)) + } + return fmt.Sprintf("#%s(%s)", *field.Name, g.dataToMotokoReturnValue(s, definitions, definitions[*field.NameData])) + case did.Optional: + return fmt.Sprintf("?%s", g.dataToMotokoReturnValue(s, definitions, t.Data)) + } + return fmt.Sprintf("%q # %q", "UNKNOWN", data) +} + +func (g *Generator) dataToMotokoString(data did.Data) string { + switch t := data.(type) { + case did.Blob: + return "Blob" + case did.Func: + return "{ /* func */ }" + case did.Record: + var fields []string + for _, v := range t { + if v.Name != nil { + var data string + if v.NameData != nil { + data = fmt.Sprintf("T.%s", *v.NameData) + } else { + data = g.dataToMotokoString(*v.Data) + } + fields = append(fields, fmt.Sprintf("%s : %s", *v.Name, data)) + } else { + if v.NameData != nil { + fields = append(fields, fmt.Sprintf("T.%s", *v.NameData)) + } else { + fields = append(fields, g.dataToMotokoString(*v.Data)) + } + } + } + var isTuple bool + for _, f := range fields { + if !strings.Contains(f, ":") { + isTuple = true + break + } + } + if isTuple { + return fmt.Sprintf("(%s)", strings.Join(fields, ", ")) + } + return fmt.Sprintf("{ %s }", strings.Join(fields, "; ")) + case did.Variant: + var variants []string + for _, v := range t { + if v.Name != nil { + var data string + if v.NameData != nil { + data = fmt.Sprintf("T.%s", *v.NameData) + } else { + data = g.dataToMotokoString(*v.Data) + } + variants = append(variants, fmt.Sprintf("#%s : %s", *v.Name, data)) + } else { + variants = append(variants, fmt.Sprintf("#%s", *v.NameData)) + } + } + return fmt.Sprintf("{ %s }", strings.Join(variants, "; ")) + case did.Vector: + return fmt.Sprintf("[%s]", g.dataToMotokoString(t.Data)) + case did.Optional: + return fmt.Sprintf("?%s", g.dataToMotokoString(t.Data)) + case did.Primitive: + switch t { + case "nat", "nat8", "nat16", "nat32", "nat64": + return strings.ReplaceAll(data.String(), "nat", "Nat") + case "int", "int8", "int16", "int32", "int64": + return strings.ReplaceAll(data.String(), "int", "Int") + case "text": + return "Text" + case "bool": + return "Bool" + case "null": + return "()" + default: + return t.String() + } + case did.Principal: + return "Principal" + case did.DataId: + return fmt.Sprintf("T.%s", string(t)) + default: + panic(fmt.Sprintf("unknown type: %T", t)) + } +} + func (g *Generator) dataToString(prefix string, data did.Data) string { switch t := data.(type) { case did.Blob: @@ -357,6 +609,23 @@ func (g *Generator) dataToString(prefix string, data did.Data) string { } } +type actorArgs struct { + CanisterName string + Methods []actorArgsMethod +} + +type actorArgsMethod struct { + Name string + Type string + ArgumentTypes []agentArgsMethodArgument + ReturnTypes []string + ReturnValues []string +} + +type actorTypesArgs struct { + Definitions []agentArgsDefinition +} + type agentArgs struct { AgentName string CanisterName string diff --git a/gen/templates/actor_mo.gotmpl b/gen/templates/actor_mo.gotmpl new file mode 100644 index 0000000..b181a34 --- /dev/null +++ b/gen/templates/actor_mo.gotmpl @@ -0,0 +1,12 @@ +// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. +import T "types"; + +import { principalOfBlob } = "mo:⛔"; + +actor class {{ .CanisterName }}() : async actor {} { +{{- range .Methods }} + public {{ .Type}} func {{ .Name }}({{ range $i, $e := .ArgumentTypes }}{{ if $i }}, {{ end }}{{ $e.Name }} : {{ $e.Type }}{{ end }}) : async ({{ range $i, $e := .ReturnTypes }}{{ if $i }}, {{ end }}{{ $e }}{{ end }}) { + ({{ range $i, $e := .ReturnValues }}{{ if $i }}, {{ end }}{{ $e }}{{ end }}) + }; +{{- end }} +} diff --git a/gen/templates/agent.gotmpl b/gen/templates/agent.gotmpl index b5062bb..90ddad1 100644 --- a/gen/templates/agent.gotmpl +++ b/gen/templates/agent.gotmpl @@ -34,17 +34,13 @@ func New{{ .AgentName }}Agent(canisterId principal.Principal, config agent.Confi // {{ .Name }} calls the "{{ .RawName }}" method on the "{{ $.CanisterName }}" canister. func (a {{ $.AgentName }}Agent) {{ .Name }}({{ range $i, $e := .ArgumentTypes }}{{ if $i }}, {{ end }}{{ $e.Name }} {{ $e.Type }}{{ end }}) {{ if .ReturnTypes }}({{ range .ReturnTypes }}*{{ . }}, {{ end }}error){{ else }}error{{ end }} { - args, err := idl.Marshal([]any{{ "{" }}{{ range $i, $e := .ArgumentTypes }}{{ if $i }}, {{ end }}{{ $e.Name }}{{ end }}{{ "}" }}) - if err != nil { - return {{ range .ReturnTypes }}nil, {{ end }}err - } {{ range $i, $e := .ReturnTypes -}} var r{{ $i }} {{ $e }} {{ end -}} if err := a.a.{{ .Type }}( a.canisterId, "{{ .RawName }}", - args, + []any{{ "{" }}{{ range $i, $e := .ArgumentTypes }}{{ if $i }}, {{ end }}{{ $e.Name }}{{ end }}{{ "}" }}, []any{{ "{" }}{{ range $i, $e := .ReturnTypes }}{{ if $i }}, {{ end }}&r{{ $i }}{{ end }}{{ "}"}}, ); err != nil { return {{ range .ReturnTypes }}nil, {{ end }}err diff --git a/gen/templates/agent_test.gotmpl b/gen/templates/agent_test.gotmpl index 79c2dcb..2c72caa 100644 --- a/gen/templates/agent_test.gotmpl +++ b/gen/templates/agent_test.gotmpl @@ -1,4 +1,4 @@ -// Automatically generated by https://github.com/aviate-labs/agent-go. +// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. package {{ .PackageName }}_test import ( diff --git a/gen/templates/types_mo.gotmpl b/gen/templates/types_mo.gotmpl new file mode 100644 index 0000000..2059b64 --- /dev/null +++ b/gen/templates/types_mo.gotmpl @@ -0,0 +1,6 @@ +// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. +module T { +{{- range .Definitions }} + public type {{ .Name }} = {{ .Type }}; +{{- end }} +}; diff --git a/ic/assetstorage/actor.mo b/ic/assetstorage/actor.mo new file mode 100755 index 0000000..6e37d25 --- /dev/null +++ b/ic/assetstorage/actor.mo @@ -0,0 +1,106 @@ +// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. +import T "types"; + +import { principalOfBlob } = "mo:⛔"; + +actor class assetstorage() : async actor {} { + public query func api_version() : async (Nat16) { + (37567) + }; + public query func get(arg0 : { key : T.Key; accept_encodings : [Text] }) : async ({ content : Blob; content_type : Text; content_encoding : Text; sha256 : ?Blob; total_length : Nat }) { + ({ content = "xD29BA3285331F6C7F0D655473EECC726ACDC040F58EA6EB25E7F29AF0D9A0D1C"; content_type = "16783008128760111668"; content_encoding = "17950520798700563169"; sha256 = ?"x9CB2427F6FE653F6B62FBA96D8F1E12A8E56D5C2F78BFBBC1AA2123F3F351627"; total_length = 6026846697888358752 }) + }; + public query func get_chunk(arg0 : { key : T.Key; content_encoding : Text; index : Nat; sha256 : ?Blob }) : async ({ content : Blob }) { + ({ content = "xD29BA3285331F6C7F0D655473EECC726ACDC040F58EA6EB25E7F29AF0D9A0D1C" }) + }; + public query func list(arg0 : { }) : async ([{ key : T.Key; content_type : Text; encodings : [{ content_encoding : Text; sha256 : ?Blob; length : Nat; modified : T.Time }] }]) { + ([ { key = "10947193270334582983"; content_type = "14796593089282320071"; encodings = [ ] }, { key = "5581137331052452365"; content_type = "16783008128760111668"; encodings = [ { content_encoding = "12417521964141425308"; sha256 = ?"xF6B62FBA96D8F1E12A8E56D5C2F78BFBBC1AA2123F3F351627CDA4F460215FDF"; length = 6761596587761439523; modified = 10710614497258299314 } ] }, { key = "15136801312447304127"; content_type = "162152548071980469"; encodings = [ { content_encoding = "14077209220119134463"; sha256 = ?"xD3C55B521FA7E06E7250741B34B1DAA9B202CC3344785BC76BE335FD22FFB6C9"; length = 2084077193164783305; modified = 13391675440417614532 }, { content_encoding = "14968975491899110795"; sha256 = ?"x37C657F58FE763E151AE30313D91840FE735F3F6150AB1E806425DC06D370BF7"; length = 2352680325195863822; modified = 14128014930335967750 } ] }, { key = "3746323425543278841"; content_type = "8821984346850239251"; encodings = [ { content_encoding = "14462736655647055063"; sha256 = ?"xCFA664CF571B6486A80528C4DCAE1D1930B6D8706B4A7C18EE44C91F412FFD02"; length = 9929700925399154573; modified = 11088767165576575891 }, { content_encoding = "15046035820075230567"; sha256 = ?"x33CFD8BFE7A383ECAFF6D1758A17DAC3846F3083D3C758209A80969C406C0F9F"; length = 12055834449873493410; modified = 31796421242169405 }, { content_encoding = "11447805667579589575"; sha256 = ?"x36DB7871DEFE2A16CB43D7DBFF5C07226CA4A775F57295BA54EBD1D035949200"; length = 13617578955253855046; modified = 1594180888861903055 }, { content_encoding = "6239237605257051267"; sha256 = ?"x0A83E5B901801DC34B34B974BCC4F911C2DF37312B004FA56633078D52F45C95"; length = 6564397865503231339; modified = 17571980052175681961 }, { content_encoding = "14305891745011577671"; sha256 = ?"x121F7F91E31B2A591C27E24EA90A3729479AB9B9E9641D8A87074BFCDD4CA2E2"; length = 14483061483814533662; modified = 8636116459066836694 }, { content_encoding = "14155040766310771050"; sha256 = ?"xC8AB4E4984A709FFAE8CBE87BB5CE7F2DC81E2E7A27D7CB3A63FD6926CE2A6D0"; length = 5638244237989845542; modified = 11216713222199587111 }, { content_encoding = "11823872115486408554"; sha256 = ?"x950831FCD6D2699AF9998BFD7C850E5037142EB4093ABEF26890C5411F599E8D"; length = 9533094216574500419; modified = 16489285970588961804 }, { content_encoding = "10490462624386304549"; sha256 = ?"xEC5265FA86B9FDF91D5FC6B39FEC4535B8F2C60CE39721211ABDC925F8CC7C94"; length = 13758130762095906934; modified = 1365263110879385157 }, { content_encoding = "112410521269379018"; sha256 = ?"x8A2CF08ABE41AB318D2ED03D6B4D526C85BF2F14CDECB0C89BEEA288B3AAE000"; length = 14746017119238981010; modified = 5692415230495667644 } ] } ]) + }; + public query func certified_tree(arg0 : { }) : async ({ certificate : Blob; tree : Blob }) { + ({ certificate = "xD29BA3285331F6C7F0D655473EECC726ACDC040F58EA6EB25E7F29AF0D9A0D1C"; tree = "x34623D11F938E9E1EACE7B8F0F1D9CB2427F6FE653F6B62FBA96D8F1E12A8E56" }) + }; + public shared func create_batch(arg0 : { }) : async ({ batch_id : T.BatchId }) { + ({ batch_id = 11310281747421436882 }) + }; + public shared func create_chunk(arg0 : { batch_id : T.BatchId; content : Blob }) : async ({ chunk_id : T.ChunkId }) { + ({ chunk_id = 11310281747421436882 }) + }; + public shared func commit_batch(arg0 : T.CommitBatchArguments) : async () { + () + }; + public shared func propose_commit_batch(arg0 : T.CommitBatchArguments) : async () { + () + }; + public shared func commit_proposed_batch(arg0 : T.CommitProposedBatchArguments) : async () { + () + }; + public shared func compute_evidence(arg0 : T.ComputeEvidenceArguments) : async (?Blob) { + (?"xD29BA3285331F6C7F0D655473EECC726ACDC040F58EA6EB25E7F29AF0D9A0D1C") + }; + public shared func delete_batch(arg0 : T.DeleteBatchArguments) : async () { + () + }; + public shared func create_asset(arg0 : T.CreateAssetArguments) : async () { + () + }; + public shared func set_asset_content(arg0 : T.SetAssetContentArguments) : async () { + () + }; + public shared func unset_asset_content(arg0 : T.UnsetAssetContentArguments) : async () { + () + }; + public shared func delete_asset(arg0 : T.DeleteAssetArguments) : async () { + () + }; + public shared func clear(arg0 : T.ClearArguments) : async () { + () + }; + public shared func store(arg0 : { key : T.Key; content_type : Text; content_encoding : Text; content : Blob; sha256 : ?Blob }) : async () { + () + }; + public query func http_request(arg0 : T.HttpRequest) : async (T.HttpResponse) { + ({ status_code = 37567; headers = [ ( "14796593089282320071", "10425597289412325098" ), ( "5581137331052452365", "16783008128760111668" ), ( "17950520798700563169", "12417521964141425308" ), ( "5040047599884678902", "14841545318558739169" ), ( "11042565298778340235", "7634908469330851135" ) ]; body = "x60215FDF23A9A3239303A84504D6B2DF3A5323BFA3BF91167098B810B53D4123"; streaming_strategy = ?#Callback({ callback = { /* func */ }; token = { key = "14077209220119134463"; content_encoding = "3666113849647154643"; index = 10714402281011311214; sha256 = ?"xDAA9B202CC3344785BC76BE335FD22FFB6C97165F2C97E144F2A21ECC42A6A65" } }) }) + }; + public query func http_request_streaming_callback(arg0 : T.StreamingCallbackToken) : async (?T.StreamingCallbackHttpResponse) { + (?{ body = "xD29BA3285331F6C7F0D655473EECC726ACDC040F58EA6EB25E7F29AF0D9A0D1C"; token = ?{ key = "16783008128760111668"; content_encoding = "17950520798700563169"; index = 12417521964141425308; sha256 = ?"xF6B62FBA96D8F1E12A8E56D5C2F78BFBBC1AA2123F3F351627CDA4F460215FDF" } }) + }; + public shared func authorize(arg0 : Principal) : async () { + () + }; + public shared func deauthorize(arg0 : Principal) : async () { + () + }; + public query func list_authorized() : async ([Principal]) { + ([ principalOfBlob("xC7F0D655473EECC726ACDC040F58EA6EB25E7F29AF0D9A0D1CD52E7434623D11"), principalOfBlob("xE1EACE7B8F0F1D9CB2427F6FE653F6B62FBA96D8F1E12A8E56D5C2F78BFBBC1A"), principalOfBlob("x3F351627CDA4F460215FDF23A9A3239303A84504D6B2DF3A5323BFA3BF911670"), principalOfBlob("xB53D4123E21440C05493AA5C742BFF000E92334B5CD3C55B521FA7E06E725074") ]) + }; + public shared func grant_permission(arg0 : T.GrantPermission) : async () { + () + }; + public shared func revoke_permission(arg0 : T.RevokePermission) : async () { + () + }; + public query func list_permitted(arg0 : T.ListPermitted) : async ([Principal]) { + ([ principalOfBlob("xC7F0D655473EECC726ACDC040F58EA6EB25E7F29AF0D9A0D1CD52E7434623D11"), principalOfBlob("xE1EACE7B8F0F1D9CB2427F6FE653F6B62FBA96D8F1E12A8E56D5C2F78BFBBC1A"), principalOfBlob("x3F351627CDA4F460215FDF23A9A3239303A84504D6B2DF3A5323BFA3BF911670"), principalOfBlob("xB53D4123E21440C05493AA5C742BFF000E92334B5CD3C55B521FA7E06E725074") ]) + }; + public shared func take_ownership() : async () { + () + }; + public query func get_asset_properties(arg0 : T.Key) : async ({ max_age : ?Nat64; headers : ?[T.HeaderField]; allow_raw_access : ?Bool; is_aliased : ?Bool }) { + ({ max_age = ?11310281747421436882; headers = ?[ ( "14796593089282320071", "10425597289412325098" ), ( "5581137331052452365", "16783008128760111668" ), ( "17950520798700563169", "12417521964141425308" ), ( "5040047599884678902", "14841545318558739169" ), ( "11042565298778340235", "7634908469330851135" ) ]; allow_raw_access = ?true; is_aliased = ?false }) + }; + public shared func set_asset_properties(arg0 : T.SetAssetPropertiesArguments) : async () { + () + }; + public shared func validate_grant_permission(arg0 : T.GrantPermission) : async (T.ValidationResult) { + (#Ok("10947193270334582983")) + }; + public shared func validate_revoke_permission(arg0 : T.RevokePermission) : async (T.ValidationResult) { + (#Ok("10947193270334582983")) + }; + public shared func validate_take_ownership() : async (T.ValidationResult) { + (#Ok("10947193270334582983")) + }; + public shared func validate_commit_proposed_batch(arg0 : T.CommitProposedBatchArguments) : async (T.ValidationResult) { + (#Ok("10947193270334582983")) + }; +} diff --git a/ic/assetstorage/agent.go b/ic/assetstorage/agent.go index 6774592..eb06ab4 100755 --- a/ic/assetstorage/agent.go +++ b/ic/assetstorage/agent.go @@ -28,15 +28,11 @@ func NewAgent(canisterId principal.Principal, config agent.Config) (*Agent, erro // ApiVersion calls the "api_version" method on the "assetstorage" canister. func (a Agent) ApiVersion() (*uint16, error) { - args, err := idl.Marshal([]any{}) - if err != nil { - return nil, err - } var r0 uint16 if err := a.a.Query( a.canisterId, "api_version", - args, + []any{}, []any{&r0}, ); err != nil { return nil, err @@ -46,14 +42,10 @@ func (a Agent) ApiVersion() (*uint16, error) { // Authorize calls the "authorize" method on the "assetstorage" canister. func (a Agent) Authorize(arg0 principal.Principal) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "authorize", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -67,10 +59,6 @@ func (a Agent) CertifiedTree(arg0 struct { Certificate []byte `ic:"certificate"` Tree []byte `ic:"tree"` }, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 struct { Certificate []byte `ic:"certificate"` Tree []byte `ic:"tree"` @@ -78,7 +66,7 @@ func (a Agent) CertifiedTree(arg0 struct { if err := a.a.Query( a.canisterId, "certified_tree", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -88,14 +76,10 @@ func (a Agent) CertifiedTree(arg0 struct { // Clear calls the "clear" method on the "assetstorage" canister. func (a Agent) Clear(arg0 ClearArguments) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "clear", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -105,14 +89,10 @@ func (a Agent) Clear(arg0 ClearArguments) error { // CommitBatch calls the "commit_batch" method on the "assetstorage" canister. func (a Agent) CommitBatch(arg0 CommitBatchArguments) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "commit_batch", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -122,14 +102,10 @@ func (a Agent) CommitBatch(arg0 CommitBatchArguments) error { // CommitProposedBatch calls the "commit_proposed_batch" method on the "assetstorage" canister. func (a Agent) CommitProposedBatch(arg0 CommitProposedBatchArguments) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "commit_proposed_batch", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -139,15 +115,11 @@ func (a Agent) CommitProposedBatch(arg0 CommitProposedBatchArguments) error { // ComputeEvidence calls the "compute_evidence" method on the "assetstorage" canister. func (a Agent) ComputeEvidence(arg0 ComputeEvidenceArguments) (**[]byte, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 *[]byte if err := a.a.Call( a.canisterId, "compute_evidence", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -157,14 +129,10 @@ func (a Agent) ComputeEvidence(arg0 ComputeEvidenceArguments) (**[]byte, error) // CreateAsset calls the "create_asset" method on the "assetstorage" canister. func (a Agent) CreateAsset(arg0 CreateAssetArguments) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "create_asset", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -177,17 +145,13 @@ func (a Agent) CreateBatch(arg0 struct { }) (*struct { BatchId BatchId `ic:"batch_id"` }, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 struct { BatchId BatchId `ic:"batch_id"` } if err := a.a.Call( a.canisterId, "create_batch", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -202,17 +166,13 @@ func (a Agent) CreateChunk(arg0 struct { }) (*struct { ChunkId ChunkId `ic:"chunk_id"` }, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 struct { ChunkId ChunkId `ic:"chunk_id"` } if err := a.a.Call( a.canisterId, "create_chunk", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -222,14 +182,10 @@ func (a Agent) CreateChunk(arg0 struct { // Deauthorize calls the "deauthorize" method on the "assetstorage" canister. func (a Agent) Deauthorize(arg0 principal.Principal) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "deauthorize", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -239,14 +195,10 @@ func (a Agent) Deauthorize(arg0 principal.Principal) error { // DeleteAsset calls the "delete_asset" method on the "assetstorage" canister. func (a Agent) DeleteAsset(arg0 DeleteAssetArguments) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "delete_asset", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -256,14 +208,10 @@ func (a Agent) DeleteAsset(arg0 DeleteAssetArguments) error { // DeleteBatch calls the "delete_batch" method on the "assetstorage" canister. func (a Agent) DeleteBatch(arg0 DeleteBatchArguments) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "delete_batch", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -282,10 +230,6 @@ func (a Agent) Get(arg0 struct { Sha256 *[]byte `ic:"sha256,omitempty"` TotalLength idl.Nat `ic:"total_length"` }, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 struct { Content []byte `ic:"content"` ContentType string `ic:"content_type"` @@ -296,7 +240,7 @@ func (a Agent) Get(arg0 struct { if err := a.a.Query( a.canisterId, "get", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -311,10 +255,6 @@ func (a Agent) GetAssetProperties(key Key) (*struct { AllowRawAccess *bool `ic:"allow_raw_access,omitempty"` IsAliased *bool `ic:"is_aliased,omitempty"` }, error) { - args, err := idl.Marshal([]any{key}) - if err != nil { - return nil, err - } var r0 struct { MaxAge *uint64 `ic:"max_age,omitempty"` Headers *[]HeaderField `ic:"headers,omitempty"` @@ -324,7 +264,7 @@ func (a Agent) GetAssetProperties(key Key) (*struct { if err := a.a.Query( a.canisterId, "get_asset_properties", - args, + []any{key}, []any{&r0}, ); err != nil { return nil, err @@ -341,17 +281,13 @@ func (a Agent) GetChunk(arg0 struct { }) (*struct { Content []byte `ic:"content"` }, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 struct { Content []byte `ic:"content"` } if err := a.a.Query( a.canisterId, "get_chunk", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -361,14 +297,10 @@ func (a Agent) GetChunk(arg0 struct { // GrantPermission calls the "grant_permission" method on the "assetstorage" canister. func (a Agent) GrantPermission(arg0 GrantPermission) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "grant_permission", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -378,15 +310,11 @@ func (a Agent) GrantPermission(arg0 GrantPermission) error { // HttpRequest calls the "http_request" method on the "assetstorage" canister. func (a Agent) HttpRequest(request HttpRequest) (*HttpResponse, error) { - args, err := idl.Marshal([]any{request}) - if err != nil { - return nil, err - } var r0 HttpResponse if err := a.a.Query( a.canisterId, "http_request", - args, + []any{request}, []any{&r0}, ); err != nil { return nil, err @@ -396,15 +324,11 @@ func (a Agent) HttpRequest(request HttpRequest) (*HttpResponse, error) { // HttpRequestStreamingCallback calls the "http_request_streaming_callback" method on the "assetstorage" canister. func (a Agent) HttpRequestStreamingCallback(token StreamingCallbackToken) (**StreamingCallbackHttpResponse, error) { - args, err := idl.Marshal([]any{token}) - if err != nil { - return nil, err - } var r0 *StreamingCallbackHttpResponse if err := a.a.Query( a.canisterId, "http_request_streaming_callback", - args, + []any{token}, []any{&r0}, ); err != nil { return nil, err @@ -424,10 +348,6 @@ func (a Agent) List(arg0 struct { Modified Time `ic:"modified"` } `ic:"encodings"` }, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 []struct { Key Key `ic:"key"` ContentType string `ic:"content_type"` @@ -441,7 +361,7 @@ func (a Agent) List(arg0 struct { if err := a.a.Query( a.canisterId, "list", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -451,15 +371,11 @@ func (a Agent) List(arg0 struct { // ListAuthorized calls the "list_authorized" method on the "assetstorage" canister. func (a Agent) ListAuthorized() (*[]principal.Principal, error) { - args, err := idl.Marshal([]any{}) - if err != nil { - return nil, err - } var r0 []principal.Principal if err := a.a.Query( a.canisterId, "list_authorized", - args, + []any{}, []any{&r0}, ); err != nil { return nil, err @@ -469,15 +385,11 @@ func (a Agent) ListAuthorized() (*[]principal.Principal, error) { // ListPermitted calls the "list_permitted" method on the "assetstorage" canister. func (a Agent) ListPermitted(arg0 ListPermitted) (*[]principal.Principal, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 []principal.Principal if err := a.a.Query( a.canisterId, "list_permitted", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -487,14 +399,10 @@ func (a Agent) ListPermitted(arg0 ListPermitted) (*[]principal.Principal, error) // ProposeCommitBatch calls the "propose_commit_batch" method on the "assetstorage" canister. func (a Agent) ProposeCommitBatch(arg0 CommitBatchArguments) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "propose_commit_batch", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -504,14 +412,10 @@ func (a Agent) ProposeCommitBatch(arg0 CommitBatchArguments) error { // RevokePermission calls the "revoke_permission" method on the "assetstorage" canister. func (a Agent) RevokePermission(arg0 RevokePermission) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "revoke_permission", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -521,14 +425,10 @@ func (a Agent) RevokePermission(arg0 RevokePermission) error { // SetAssetContent calls the "set_asset_content" method on the "assetstorage" canister. func (a Agent) SetAssetContent(arg0 SetAssetContentArguments) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "set_asset_content", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -538,14 +438,10 @@ func (a Agent) SetAssetContent(arg0 SetAssetContentArguments) error { // SetAssetProperties calls the "set_asset_properties" method on the "assetstorage" canister. func (a Agent) SetAssetProperties(arg0 SetAssetPropertiesArguments) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "set_asset_properties", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -561,14 +457,10 @@ func (a Agent) Store(arg0 struct { Content []byte `ic:"content"` Sha256 *[]byte `ic:"sha256,omitempty"` }) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "store", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -578,14 +470,10 @@ func (a Agent) Store(arg0 struct { // TakeOwnership calls the "take_ownership" method on the "assetstorage" canister. func (a Agent) TakeOwnership() error { - args, err := idl.Marshal([]any{}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "take_ownership", - args, + []any{}, []any{}, ); err != nil { return err @@ -595,14 +483,10 @@ func (a Agent) TakeOwnership() error { // UnsetAssetContent calls the "unset_asset_content" method on the "assetstorage" canister. func (a Agent) UnsetAssetContent(arg0 UnsetAssetContentArguments) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "unset_asset_content", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -612,15 +496,11 @@ func (a Agent) UnsetAssetContent(arg0 UnsetAssetContentArguments) error { // ValidateCommitProposedBatch calls the "validate_commit_proposed_batch" method on the "assetstorage" canister. func (a Agent) ValidateCommitProposedBatch(arg0 CommitProposedBatchArguments) (*ValidationResult, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 ValidationResult if err := a.a.Call( a.canisterId, "validate_commit_proposed_batch", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -630,15 +510,11 @@ func (a Agent) ValidateCommitProposedBatch(arg0 CommitProposedBatchArguments) (* // ValidateGrantPermission calls the "validate_grant_permission" method on the "assetstorage" canister. func (a Agent) ValidateGrantPermission(arg0 GrantPermission) (*ValidationResult, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 ValidationResult if err := a.a.Call( a.canisterId, "validate_grant_permission", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -648,15 +524,11 @@ func (a Agent) ValidateGrantPermission(arg0 GrantPermission) (*ValidationResult, // ValidateRevokePermission calls the "validate_revoke_permission" method on the "assetstorage" canister. func (a Agent) ValidateRevokePermission(arg0 RevokePermission) (*ValidationResult, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 ValidationResult if err := a.a.Call( a.canisterId, "validate_revoke_permission", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -666,15 +538,11 @@ func (a Agent) ValidateRevokePermission(arg0 RevokePermission) (*ValidationResul // ValidateTakeOwnership calls the "validate_take_ownership" method on the "assetstorage" canister. func (a Agent) ValidateTakeOwnership() (*ValidationResult, error) { - args, err := idl.Marshal([]any{}) - if err != nil { - return nil, err - } var r0 ValidationResult if err := a.a.Call( a.canisterId, "validate_take_ownership", - args, + []any{}, []any{&r0}, ); err != nil { return nil, err diff --git a/ic/assetstorage/agent_test.go b/ic/assetstorage/agent_test.go index 4509743..220fcf5 100755 --- a/ic/assetstorage/agent_test.go +++ b/ic/assetstorage/agent_test.go @@ -1,4 +1,4 @@ -// Automatically generated by https://github.com/aviate-labs/agent-go. +// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. package assetstorage_test import ( diff --git a/ic/assetstorage/types.mo b/ic/assetstorage/types.mo new file mode 100755 index 0000000..fae4e91 --- /dev/null +++ b/ic/assetstorage/types.mo @@ -0,0 +1,29 @@ +// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. +module T { + public type BatchId = Nat; + public type ChunkId = Nat; + public type Key = Text; + public type Time = Int; + public type CreateAssetArguments = { key : T.Key; content_type : Text; max_age : ?Nat64; headers : ?[T.HeaderField]; enable_aliasing : ?Bool; allow_raw_access : ?Bool }; + public type SetAssetContentArguments = { key : T.Key; content_encoding : Text; chunk_ids : [T.ChunkId]; sha256 : ?Blob }; + public type UnsetAssetContentArguments = { key : T.Key; content_encoding : Text }; + public type DeleteAssetArguments = { key : T.Key }; + public type ClearArguments = { }; + public type BatchOperationKind = { #CreateAsset : T.CreateAssetArguments; #SetAssetContent : T.SetAssetContentArguments; #SetAssetProperties : T.SetAssetPropertiesArguments; #UnsetAssetContent : T.UnsetAssetContentArguments; #DeleteAsset : T.DeleteAssetArguments; #Clear : T.ClearArguments }; + public type CommitBatchArguments = { batch_id : T.BatchId; operations : [T.BatchOperationKind] }; + public type CommitProposedBatchArguments = { batch_id : T.BatchId; evidence : Blob }; + public type ComputeEvidenceArguments = { batch_id : T.BatchId; max_iterations : ?Nat16 }; + public type DeleteBatchArguments = { batch_id : T.BatchId }; + public type HeaderField = (Text, Text); + public type HttpRequest = { method : Text; url : Text; headers : [T.HeaderField]; body : Blob; certificate_version : ?Nat16 }; + public type HttpResponse = { status_code : Nat16; headers : [T.HeaderField]; body : Blob; streaming_strategy : ?T.StreamingStrategy }; + public type StreamingCallbackHttpResponse = { body : Blob; token : ?T.StreamingCallbackToken }; + public type StreamingCallbackToken = { key : T.Key; content_encoding : Text; index : Nat; sha256 : ?Blob }; + public type StreamingStrategy = { #Callback : { callback : { /* func */ }; token : T.StreamingCallbackToken } }; + public type SetAssetPropertiesArguments = { key : T.Key; max_age : ??Nat64; headers : ??[T.HeaderField]; allow_raw_access : ??Bool; is_aliased : ??Bool }; + public type Permission = { #Commit; #ManagePermissions; #Prepare }; + public type GrantPermission = { to_principal : Principal; permission : T.Permission }; + public type RevokePermission = { of_principal : Principal; permission : T.Permission }; + public type ListPermitted = { permission : T.Permission }; + public type ValidationResult = { #Ok : Text; #Err : Text }; +}; diff --git a/ic/cmc/actor.mo b/ic/cmc/actor.mo new file mode 100755 index 0000000..ba63ad9 --- /dev/null +++ b/ic/cmc/actor.mo @@ -0,0 +1,19 @@ +// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. +import T "types"; + +import { principalOfBlob } = "mo:⛔"; + +actor class cmc() : async actor {} { + public shared func notify_top_up(arg0 : T.NotifyTopUpArg) : async (T.NotifyTopUpResult) { + (#Ok(13928505266879913405)) + }; + public shared func notify_create_canister(arg0 : T.NotifyCreateCanisterArg) : async (T.NotifyCreateCanisterResult) { + (#Ok(principalOfBlob("xBDDD886CBEFD4B2A492BD37EED100C4A92C2724DFDEEA442723ED5975AE7B291"))) + }; + public query func get_icp_xdr_conversion_rate() : async (T.IcpXdrConversionRateResponse) { + ({ data = { timestamp_seconds = 7869213255852361324; xdr_permyriad_per_icp = 13928505266879913405 }; hash_tree = "x2A492BD37EED100C4A92C2724DFDEEA442723ED5975AE7B29122E0DDF194DD7E"; certificate = "x5528C3C9A6BA5F6F214EDB0ADC761D7824266830A884EE0F1DD3A30544A705F3" }) + }; + public query func get_subnet_types_to_subnets() : async (T.SubnetTypesToSubnetsResponse) { + ({ data = [ ( "13928505266879913405", [ principalOfBlob("x0C4A92C2724DFDEEA442723ED5975AE7B29122E0DDF194DD7EA9FD965528C3C9"), principalOfBlob("x6F214EDB0ADC761D7824266830A884EE0F1DD3A30544A705F333F71702C7A660"), principalOfBlob("x951AC7ABA75404FF9F4FAA7D514C6DECB06637E868B117928E31FF4B3AF537E5"), principalOfBlob("x5560FF1A52DD6373BFBDD2A9248390071788F3C08BB33ED100CEF45D83C58237"), principalOfBlob("x7DF7405C7D3A4E4CABBE52B063DD16C97B3ADC25E4DCF546CF04F19365EFF436"), principalOfBlob("x42B7DFC7DFEC782917263A657D0DE6693F5C99FDE433CA01705CF05DD2070AE9") ] ), ( "4079598243291951032", [ principalOfBlob("xB9A37D98C2FAE8511AE12915936EAEEE9E788F297C09E28F0ADF120B0A296CEB"), principalOfBlob("xC2A3628B06F9DBA38FB72ED9EA2FA0155AA8C3454A0B6B7D243B879C0D565FF3"), principalOfBlob("xF96C562E9C04CE4151D4C6724C48A5DA0BDA2E89A4E3D812E5053A5878CF966B"), principalOfBlob("x7074BD42188B8EA0EA45A26782C1685E4ABFD47263EE88B87F20F20BDD7AC948"), principalOfBlob("xA589BEB48C3C69E8E292102556CA5C2482A9F277195ACF93DDE4EA792EF32DDD") ] ), ( "3237536108921815135", [ ] ), ( "2209486570766690869", [ principalOfBlob("x7A1A00D7528980DC4B5D2C61CD124CB667E538083C45AC24323A6B09F1937EBD"), principalOfBlob("x9784DDD5730BBE38F428F80C9C5075CB27A3C3C5B515DC9FEC1E1D8143D3F6D3"), principalOfBlob("x35AACBAB8D6525C9414CD74467FBE7DD91F2B774B08AEBE215950A3D06E2FC3C"), principalOfBlob("xBEBAA72E4D2773DBE87344D3B07940517CCF45A7E25F9D25DB14CCCF80D0129B"), principalOfBlob("x99C6BD7932FCCCD5EDDBD6FC58A31F4AE5BEA0F9682A1272F34D9CBB4554471B") ] ) ] }) + }; +} diff --git a/ic/cmc/agent.go b/ic/cmc/agent.go index 734baa8..d2d49e3 100755 --- a/ic/cmc/agent.go +++ b/ic/cmc/agent.go @@ -32,15 +32,11 @@ func NewAgent(canisterId principal.Principal, config agent.Config) (*Agent, erro // GetIcpXdrConversionRate calls the "get_icp_xdr_conversion_rate" method on the "cmc" canister. func (a Agent) GetIcpXdrConversionRate() (*IcpXdrConversionRateResponse, error) { - args, err := idl.Marshal([]any{}) - if err != nil { - return nil, err - } var r0 IcpXdrConversionRateResponse if err := a.a.Query( a.canisterId, "get_icp_xdr_conversion_rate", - args, + []any{}, []any{&r0}, ); err != nil { return nil, err @@ -50,15 +46,11 @@ func (a Agent) GetIcpXdrConversionRate() (*IcpXdrConversionRateResponse, error) // GetSubnetTypesToSubnets calls the "get_subnet_types_to_subnets" method on the "cmc" canister. func (a Agent) GetSubnetTypesToSubnets() (*SubnetTypesToSubnetsResponse, error) { - args, err := idl.Marshal([]any{}) - if err != nil { - return nil, err - } var r0 SubnetTypesToSubnetsResponse if err := a.a.Query( a.canisterId, "get_subnet_types_to_subnets", - args, + []any{}, []any{&r0}, ); err != nil { return nil, err @@ -68,15 +60,11 @@ func (a Agent) GetSubnetTypesToSubnets() (*SubnetTypesToSubnetsResponse, error) // NotifyCreateCanister calls the "notify_create_canister" method on the "cmc" canister. func (a Agent) NotifyCreateCanister(arg0 NotifyCreateCanisterArg) (*NotifyCreateCanisterResult, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 NotifyCreateCanisterResult if err := a.a.Call( a.canisterId, "notify_create_canister", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -86,15 +74,11 @@ func (a Agent) NotifyCreateCanister(arg0 NotifyCreateCanisterArg) (*NotifyCreate // NotifyTopUp calls the "notify_top_up" method on the "cmc" canister. func (a Agent) NotifyTopUp(arg0 NotifyTopUpArg) (*NotifyTopUpResult, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 NotifyTopUpResult if err := a.a.Call( a.canisterId, "notify_top_up", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err diff --git a/ic/cmc/agent_test.go b/ic/cmc/agent_test.go index 0d158f6..3b0cc5e 100755 --- a/ic/cmc/agent_test.go +++ b/ic/cmc/agent_test.go @@ -1,4 +1,4 @@ -// Automatically generated by https://github.com/aviate-labs/agent-go. +// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. package cmc_test import ( diff --git a/ic/cmc/types.mo b/ic/cmc/types.mo new file mode 100755 index 0000000..bba0829 --- /dev/null +++ b/ic/cmc/types.mo @@ -0,0 +1,16 @@ +// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. +module T { + public type Cycles = Nat; + public type BlockIndex = Nat64; + public type NotifyTopUpArg = { block_index : T.BlockIndex; canister_id : Principal }; + public type NotifyCreateCanisterArg = { block_index : T.BlockIndex; controller : Principal; subnet_type : ?Text }; + public type NotifyError = { #Refunded : { reason : Text; block_index : ?T.BlockIndex }; #Processing; #TransactionTooOld : T.BlockIndex; #InvalidTransaction : Text; #Other : { error_code : Nat64; error_message : Text } }; + public type NotifyTopUpResult = { #Ok : T.Cycles; #Err : T.NotifyError }; + public type NotifyCreateCanisterResult = { #Ok : Principal; #Err : T.NotifyError }; + public type IcpXdrConversionRate = { timestamp_seconds : Nat64; xdr_permyriad_per_icp : Nat64 }; + public type IcpXdrConversionRateResponse = { data : T.IcpXdrConversionRate; hash_tree : Blob; certificate : Blob }; + public type SubnetTypesToSubnetsResponse = { data : [(Text, [Principal])] }; + public type AccountIdentifier = { bytes : Blob }; + public type ExchangeRateCanister = { #Set : Principal; #Unset }; + public type CyclesCanisterInitPayload = { ledger_canister_id : ?Principal; governance_canister_id : ?Principal; minting_account_id : ?T.AccountIdentifier; last_purged_notification : ?Nat64; exchange_rate_canister : ?T.ExchangeRateCanister }; +}; diff --git a/ic/dfx.json b/ic/dfx.json new file mode 100644 index 0000000..97d0c02 --- /dev/null +++ b/ic/dfx.json @@ -0,0 +1,8 @@ +{ + "canisters": { + "assetstorage": { + "type": "motoko", + "main": "assetstorage/actor.mo" + } + } +} diff --git a/ic/ic_test.go b/ic/ic_test.go new file mode 100644 index 0000000..eb213ae --- /dev/null +++ b/ic/ic_test.go @@ -0,0 +1,85 @@ +package ic_test + +import ( + "encoding/json" + "fmt" + "github.com/aviate-labs/agent-go" + "github.com/aviate-labs/agent-go/ic/assetstorage" + "github.com/aviate-labs/agent-go/principal" + "net/url" + "os" + "os/exec" + "strings" + "testing" +) + +func TestModules(t *testing.T) { + homeDir, _ := os.UserHomeDir() + rawNetworksConfig, err := os.ReadFile(fmt.Sprintf("%s/.config/dfx/networks.json", homeDir)) + if err != nil { + t.Skip(err) + } + var networksConfig map[string]map[string]string + if err := json.Unmarshal(rawNetworksConfig, &networksConfig); err != nil { + t.Fatal(err) + } + host, err := url.Parse(fmt.Sprintf("http://%s", networksConfig["local"]["bind"])) + if err != nil { + t.Fatal(err) + } + t.Log("Using DFX host:", host) + + dfxPath, err := exec.LookPath("dfx") + if err != nil { + t.Skip(err) + } + start := exec.Command(dfxPath, "start", "--background", "--clean", "--artificial-delay=10") + if err := start.Start(); err != nil { + t.Fatal(err) + } + if err := start.Wait(); err != nil { + t.Error(err) + } + t.Log("Started DFX") + defer func() { + out, _ := exec.Command(dfxPath, "stop").CombinedOutput() + t.Log(sanitizeOutput(out)) + }() + + deploy := exec.Command(dfxPath, "deploy", "--no-wallet") + if out, err := deploy.CombinedOutput(); err != nil { + t.Fatal(sanitizeOutput(out)) + } + + raw, err := os.ReadFile(".dfx/local/canister_ids.json") + if err != nil { + t.Fatal(err) + } + var m map[string]map[string]string + if err := json.Unmarshal(raw, &m); err != nil { + t.Fatal(err) + } + + t.Run("assetstorage", func(t *testing.T) { + cId, _ := principal.Decode(m["assetstorage"]["local"]) + a, err := assetstorage.NewAgent(cId, agent.Config{ + ClientConfig: &agent.ClientConfig{Host: host}, + FetchRootKey: true, + }) + if err != nil { + t.Fatal(err) + } + if _, err := a.ApiVersion(); err != nil { + t.Error(err) + } + }) +} + +func sanitizeOutput(out []byte) string { + const artifact = "\u001B(B" // Not sure where this comes from... + var s string + for _, p := range strings.Split(strings.TrimSpace(string(out)), "\n") { + s += strings.TrimSpace(strings.ReplaceAll(p, artifact, "")) + "\n" + } + return s +} diff --git a/ic/icparchive/actor.mo b/ic/icparchive/actor.mo new file mode 100755 index 0000000..9c55c8d --- /dev/null +++ b/ic/icparchive/actor.mo @@ -0,0 +1,10 @@ +// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. +import T "types"; + +import { principalOfBlob } = "mo:⛔"; + +actor class icparchive() : async actor {} { + public query func get_blocks(arg0 : T.GetBlocksArgs) : async (T.GetBlocksResult) { + (#Err(#BadFirstBlockIndex({ requested_index = 6197789885467376506; first_valid_index = 11539667703195591131 }))) + }; +} diff --git a/ic/icparchive/agent.go b/ic/icparchive/agent.go index b00005b..9ede0a1 100755 --- a/ic/icparchive/agent.go +++ b/ic/icparchive/agent.go @@ -30,15 +30,11 @@ func NewAgent(canisterId principal.Principal, config agent.Config) (*Agent, erro // GetBlocks calls the "get_blocks" method on the "icparchive" canister. func (a Agent) GetBlocks(arg0 GetBlocksArgs) (*GetBlocksResult, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 GetBlocksResult if err := a.a.Query( a.canisterId, "get_blocks", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err diff --git a/ic/icparchive/agent_test.go b/ic/icparchive/agent_test.go index 021b0fb..fa94a33 100644 --- a/ic/icparchive/agent_test.go +++ b/ic/icparchive/agent_test.go @@ -1,4 +1,4 @@ -// Automatically generated by https://github.com/aviate-labs/agent-go. +// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. package icparchive_test import ( diff --git a/ic/icparchive/types.mo b/ic/icparchive/types.mo new file mode 100755 index 0000000..c521e5e --- /dev/null +++ b/ic/icparchive/types.mo @@ -0,0 +1,15 @@ +// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. +module T { + public type BlockIndex = Nat64; + public type Memo = Nat64; + public type AccountIdentifier = Blob; + public type Tokens = { e8s : Nat64 }; + public type Timestamp = { timestamp_nanos : Nat64 }; + public type Operation = { #Mint : { to : T.AccountIdentifier; amount : T.Tokens }; #Burn : { from : T.AccountIdentifier; amount : T.Tokens }; #Transfer : { from : T.AccountIdentifier; to : T.AccountIdentifier; amount : T.Tokens; fee : T.Tokens }; #Approve : { from : T.AccountIdentifier; spender : T.AccountIdentifier; allowance_e8s : Int; fee : T.Tokens; expires_at : ?T.Timestamp }; #TransferFrom : { from : T.AccountIdentifier; to : T.AccountIdentifier; spender : T.AccountIdentifier; amount : T.Tokens; fee : T.Tokens } }; + public type Transaction = { memo : T.Memo; icrc1_memo : ?Blob; operation : ?T.Operation; created_at_time : T.Timestamp }; + public type Block = { parent_hash : ?Blob; transaction : T.Transaction; timestamp : T.Timestamp }; + public type GetBlocksArgs = { start : T.BlockIndex; length : Nat64 }; + public type BlockRange = { blocks : [T.Block] }; + public type GetBlocksError = { #BadFirstBlockIndex : { requested_index : T.BlockIndex; first_valid_index : T.BlockIndex }; #Other : { error_code : Nat64; error_message : Text } }; + public type GetBlocksResult = { #Ok : T.BlockRange; #Err : T.GetBlocksError }; +}; diff --git a/ic/icpledger/actor.mo b/ic/icpledger/actor.mo new file mode 100755 index 0000000..335c78f --- /dev/null +++ b/ic/icpledger/actor.mo @@ -0,0 +1,31 @@ +// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. +import T "types"; + +import { principalOfBlob } = "mo:⛔"; + +actor class icpledger() : async actor {} { + public shared func transfer(arg0 : T.TransferArgs) : async (T.TransferResult) { + (#Err(#TxCreatedInFuture(()))) + }; + public query func account_balance(arg0 : T.AccountBalanceArgs) : async (T.Tokens) { + ({ e8s = 6844078342166154913 }) + }; + public query func transfer_fee(arg0 : T.TransferFeeArg) : async (T.TransferFee) { + ({ transfer_fee = { e8s = 6844078342166154913 } }) + }; + public query func query_blocks(arg0 : T.GetBlocksArgs) : async (T.QueryBlocksResponse) { + ({ chain_length = 6844078342166154913; certificate = ?"x84891BC5734DC8A7DBD3D42B2C9D0A8FBBF49C31A6ECCAD50322C04AE239219A"; blocks = [ { parent_hash = ?"x267840FA60A5160796052355DC613B3B6DD17D37E39432DAB2AB61070029151D"; transaction = { memo = 11508387437776522631; icrc1_memo = ?"x15D9B71F910AE4978C6001D6EBE96441FB2F2AC1E3F491B5AD85106B4D49CAAB"; operation = ?#Burn({ from = "xF8E011AAEE68D2270B08A64D94AE3AF0629EF547A02033FD611622DAB7C219DE"; amount = { e8s = 9640862273893842221 } }); created_at_time = { timestamp_nanos = 18434941167457045861 } }; timestamp = { timestamp_nanos = 17936735417084933145 } }, { parent_hash = ?"x0F380883A19D18A66069A4DB047004E9322EFCBF4A88CD79FDA4E21739AFDF90"; transaction = { memo = 3376834384587756782; icrc1_memo = ?"x545EE2B2142EB1A745A54BC94D2210536F44E142BA3842C40F699A300C037EAE"; operation = ?#Transfer({ from = "x2F856182D3B2EEDA50CC652B61D03D35374C19FD70685A626B0BE87B14E747B5"; to = "xBFD21F5B02A9AE32607D4F702056FB42F474E2D79096BB978CE3E215F5D16941"; amount = { e8s = 2337095702201755982 }; fee = { e8s = 8119966841819193775 } }); created_at_time = { timestamp_nanos = 14630522076889513897 } }; timestamp = { timestamp_nanos = 10234017389260060020 } }, { parent_hash = ?"x7F98C824FDA6E0DA1333D8621433A7F294C20BD614EBE11CC8CA2E8861E55E80"; transaction = { memo = 15846245038892287776; icrc1_memo = ?"xE2C6C57D0E4E5BC337B01396134D52E7E0CEF8A723CB9511450F3D57D9502E93"; operation = ?#Burn({ from = "xA277B665A7186D600DB1BE3907053ADA327550CC72BE69A0039ED288EA325359"; amount = { e8s = 13388315825435817461 } }); created_at_time = { timestamp_nanos = 1037580399648321749 } }; timestamp = { timestamp_nanos = 8765815739915276449 } } ]; first_block_index = 8774201989248131967; archived_blocks = [ { start = 9990291550900519784; length = 15814546617447143983; callback = { /* func */ } }, { start = 10525394844609216418; length = 13653777742181055018; callback = { /* func */ } }, { start = 5260480757802142243; length = 6532771774582539980; callback = { /* func */ } }, { start = 16823501307558194871; length = 4710247719163020692; callback = { /* func */ } }, { start = 743139622545088781; length = 1137136953581248725; callback = { /* func */ } } ] }) + }; + public query func symbol() : async ({ symbol : Text }) { + ({ symbol = "6844078342166154913" }) + }; + public query func name() : async ({ name : Text }) { + ({ name = "6844078342166154913" }) + }; + public query func decimals() : async ({ decimals : Nat32 }) { + ({ decimals = 4273806238 }) + }; + public query func archives() : async (T.Archives) { + ({ archives = [ { canister_id = principalOfBlob("x84891BC5734DC8A7DBD3D42B2C9D0A8FBBF49C31A6ECCAD50322C04AE239219A") }, { canister_id = principalOfBlob("x8131F8664185C2267840FA60A5160796052355DC613B3B6DD17D37E39432DAB2") }, { canister_id = principalOfBlob("x0029151DF0511187CD3C8E6601B615D9B71F910AE4978C6001D6EBE96441FB2F") } ] }) + }; +} diff --git a/ic/icpledger/agent.go b/ic/icpledger/agent.go index 901c9a8..80cbdaa 100755 --- a/ic/icpledger/agent.go +++ b/ic/icpledger/agent.go @@ -34,15 +34,11 @@ func NewAgent(canisterId principal.Principal, config agent.Config) (*Agent, erro // AccountBalance calls the "account_balance" method on the "icpledger" canister. func (a Agent) AccountBalance(arg0 AccountBalanceArgs) (*Tokens, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 Tokens if err := a.a.Query( a.canisterId, "account_balance", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -52,15 +48,11 @@ func (a Agent) AccountBalance(arg0 AccountBalanceArgs) (*Tokens, error) { // Archives calls the "archives" method on the "icpledger" canister. func (a Agent) Archives() (*Archives, error) { - args, err := idl.Marshal([]any{}) - if err != nil { - return nil, err - } var r0 Archives if err := a.a.Query( a.canisterId, "archives", - args, + []any{}, []any{&r0}, ); err != nil { return nil, err @@ -72,17 +64,13 @@ func (a Agent) Archives() (*Archives, error) { func (a Agent) Decimals() (*struct { Decimals uint32 `ic:"decimals"` }, error) { - args, err := idl.Marshal([]any{}) - if err != nil { - return nil, err - } var r0 struct { Decimals uint32 `ic:"decimals"` } if err := a.a.Query( a.canisterId, "decimals", - args, + []any{}, []any{&r0}, ); err != nil { return nil, err @@ -94,17 +82,13 @@ func (a Agent) Decimals() (*struct { func (a Agent) Name() (*struct { Name string `ic:"name"` }, error) { - args, err := idl.Marshal([]any{}) - if err != nil { - return nil, err - } var r0 struct { Name string `ic:"name"` } if err := a.a.Query( a.canisterId, "name", - args, + []any{}, []any{&r0}, ); err != nil { return nil, err @@ -114,15 +98,11 @@ func (a Agent) Name() (*struct { // QueryBlocks calls the "query_blocks" method on the "icpledger" canister. func (a Agent) QueryBlocks(arg0 GetBlocksArgs) (*QueryBlocksResponse, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 QueryBlocksResponse if err := a.a.Query( a.canisterId, "query_blocks", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -134,17 +114,13 @@ func (a Agent) QueryBlocks(arg0 GetBlocksArgs) (*QueryBlocksResponse, error) { func (a Agent) Symbol() (*struct { Symbol string `ic:"symbol"` }, error) { - args, err := idl.Marshal([]any{}) - if err != nil { - return nil, err - } var r0 struct { Symbol string `ic:"symbol"` } if err := a.a.Query( a.canisterId, "symbol", - args, + []any{}, []any{&r0}, ); err != nil { return nil, err @@ -154,15 +130,11 @@ func (a Agent) Symbol() (*struct { // Transfer calls the "transfer" method on the "icpledger" canister. func (a Agent) Transfer(arg0 TransferArgs) (*TransferResult, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 TransferResult if err := a.a.Call( a.canisterId, "transfer", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -172,15 +144,11 @@ func (a Agent) Transfer(arg0 TransferArgs) (*TransferResult, error) { // TransferFee calls the "transfer_fee" method on the "icpledger" canister. func (a Agent) TransferFee(arg0 TransferFeeArg) (*TransferFee, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 TransferFee if err := a.a.Query( a.canisterId, "transfer_fee", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err diff --git a/ic/icpledger/agent_test.go b/ic/icpledger/agent_test.go index bef2aaa..f7eee47 100644 --- a/ic/icpledger/agent_test.go +++ b/ic/icpledger/agent_test.go @@ -1,4 +1,4 @@ -// Automatically generated by https://github.com/aviate-labs/agent-go. +// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. package icpledger_test import ( diff --git a/ic/icpledger/types.mo b/ic/icpledger/types.mo new file mode 100755 index 0000000..67e153e --- /dev/null +++ b/ic/icpledger/types.mo @@ -0,0 +1,26 @@ +// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. +module T { + public type Tokens = { e8s : Nat64 }; + public type TimeStamp = { timestamp_nanos : Nat64 }; + public type AccountIdentifier = Blob; + public type SubAccount = Blob; + public type BlockIndex = Nat64; + public type Transaction = { memo : T.Memo; icrc1_memo : ?Blob; operation : ?T.Operation; created_at_time : T.TimeStamp }; + public type Memo = Nat64; + public type TransferArgs = { memo : T.Memo; amount : T.Tokens; fee : T.Tokens; from_subaccount : ?T.SubAccount; to : T.AccountIdentifier; created_at_time : ?T.TimeStamp }; + public type TransferError = { #BadFee : { expected_fee : T.Tokens }; #InsufficientFunds : { balance : T.Tokens }; #TxTooOld : { allowed_window_nanos : Nat64 }; #TxCreatedInFuture : (); #TxDuplicate : { duplicate_of : T.BlockIndex } }; + public type TransferResult = { #Ok : T.BlockIndex; #Err : T.TransferError }; + public type AccountBalanceArgs = { account : T.AccountIdentifier }; + public type TransferFeeArg = { }; + public type TransferFee = { transfer_fee : T.Tokens }; + public type GetBlocksArgs = { start : T.BlockIndex; length : Nat64 }; + public type Operation = { #Mint : { to : T.AccountIdentifier; amount : T.Tokens }; #Burn : { from : T.AccountIdentifier; amount : T.Tokens }; #Transfer : { from : T.AccountIdentifier; to : T.AccountIdentifier; amount : T.Tokens; fee : T.Tokens }; #Approve : { from : T.AccountIdentifier; spender : T.AccountIdentifier; allowance_e8s : Int; fee : T.Tokens; expires_at : ?T.TimeStamp }; #TransferFrom : { from : T.AccountIdentifier; to : T.AccountIdentifier; spender : T.AccountIdentifier; amount : T.Tokens; fee : T.Tokens } }; + public type Block = { parent_hash : ?Blob; transaction : T.Transaction; timestamp : T.TimeStamp }; + public type BlockRange = { blocks : [T.Block] }; + public type QueryArchiveError = { #BadFirstBlockIndex : { requested_index : T.BlockIndex; first_valid_index : T.BlockIndex }; #Other : { error_code : Nat64; error_message : Text } }; + public type QueryArchiveResult = { #Ok : T.BlockRange; #Err : T.QueryArchiveError }; + public type QueryArchiveFn = { /* func */ }; + public type QueryBlocksResponse = { chain_length : Nat64; certificate : ?Blob; blocks : [T.Block]; first_block_index : T.BlockIndex; archived_blocks : [{ start : T.BlockIndex; length : Nat64; callback : T.QueryArchiveFn }] }; + public type Archive = { canister_id : Principal }; + public type Archives = { archives : [T.Archive] }; +}; diff --git a/ic/icrc1/actor.mo b/ic/icrc1/actor.mo new file mode 100755 index 0000000..e0e58ad --- /dev/null +++ b/ic/icrc1/actor.mo @@ -0,0 +1,37 @@ +// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. +import T "types"; + +import { principalOfBlob } = "mo:⛔"; + +actor class icrc1() : async actor {} { + public query func icrc1_metadata() : async ([(Text, T.Value)]) { + ([ ( "8461085577816129895", #Int(5878529396228072694) ), ( "17086874607426100806", #Text("10709273831789307773") ), ( "16878655614376436083", #Int(6759167820548538355) ), ( "18292591075080601467", #Nat(17811010120847317546) ), ( "18177279855461275382", #Int(5653783580888133841) ), ( "7999443096767709278", #Int(18374081214496534973) ) ]) + }; + public query func icrc1_name() : async (Text) { + ("15860260956177527794") + }; + public query func icrc1_symbol() : async (Text) { + ("15860260956177527794") + }; + public query func icrc1_decimals() : async (Nat8) { + (139) + }; + public query func icrc1_fee() : async (Nat) { + (15860260956177527794) + }; + public query func icrc1_total_supply() : async (Nat) { + (15860260956177527794) + }; + public query func icrc1_minting_account() : async (?T.Account) { + (?{ owner = principalOfBlob("xF273F5F14EF71A6741E91781D06B5D360F3EE11F56F6A4DD0F57BB94465E46E1"); subaccount = ?"xBE56FB9FA308657D273052CFFB9E73610FB5DA073D79779DC770CD9DF3FF0B39" }) + }; + public query func icrc1_balance_of(arg0 : T.Account) : async (Nat) { + (15860260956177527794) + }; + public shared func icrc1_transfer(arg0 : T.TransferArgs) : async ({ #Ok : Nat; #Err : T.TransferError }) { + (#Ok(8461085577816129895)) + }; + public query func icrc1_supported_standards() : async ([{ name : Text; url : Text }]) { + ([ { name = "8461085577816129895"; url = "17606294845520819805" }, { name = "5878529396228072694"; url = "17086874607426100806" }, { name = "12350287051990193854"; url = "10709273831789307773" }, { name = "16878655614376436083"; url = "332647831764301689" }, { name = "6759167820548538355"; url = "18292591075080601467" }, { name = "7929299208935178212"; url = "17811010120847317546" } ]) + }; +} diff --git a/ic/icrc1/agent.go b/ic/icrc1/agent.go index 2e96c3a..701d76b 100755 --- a/ic/icrc1/agent.go +++ b/ic/icrc1/agent.go @@ -33,15 +33,11 @@ func NewAgent(canisterId principal.Principal, config agent.Config) (*Agent, erro // Icrc1BalanceOf calls the "icrc1_balance_of" method on the "icrc1" canister. func (a Agent) Icrc1BalanceOf(arg0 Account) (*idl.Nat, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 idl.Nat if err := a.a.Query( a.canisterId, "icrc1_balance_of", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -51,15 +47,11 @@ func (a Agent) Icrc1BalanceOf(arg0 Account) (*idl.Nat, error) { // Icrc1Decimals calls the "icrc1_decimals" method on the "icrc1" canister. func (a Agent) Icrc1Decimals() (*uint8, error) { - args, err := idl.Marshal([]any{}) - if err != nil { - return nil, err - } var r0 uint8 if err := a.a.Query( a.canisterId, "icrc1_decimals", - args, + []any{}, []any{&r0}, ); err != nil { return nil, err @@ -69,15 +61,11 @@ func (a Agent) Icrc1Decimals() (*uint8, error) { // Icrc1Fee calls the "icrc1_fee" method on the "icrc1" canister. func (a Agent) Icrc1Fee() (*idl.Nat, error) { - args, err := idl.Marshal([]any{}) - if err != nil { - return nil, err - } var r0 idl.Nat if err := a.a.Query( a.canisterId, "icrc1_fee", - args, + []any{}, []any{&r0}, ); err != nil { return nil, err @@ -90,10 +78,6 @@ func (a Agent) Icrc1Metadata() (*[]struct { field0 string `ic:"field0"` field1 Value `ic:"field1"` }, error) { - args, err := idl.Marshal([]any{}) - if err != nil { - return nil, err - } var r0 []struct { field0 string `ic:"field0"` field1 Value `ic:"field1"` @@ -101,7 +85,7 @@ func (a Agent) Icrc1Metadata() (*[]struct { if err := a.a.Query( a.canisterId, "icrc1_metadata", - args, + []any{}, []any{&r0}, ); err != nil { return nil, err @@ -111,15 +95,11 @@ func (a Agent) Icrc1Metadata() (*[]struct { // Icrc1MintingAccount calls the "icrc1_minting_account" method on the "icrc1" canister. func (a Agent) Icrc1MintingAccount() (**Account, error) { - args, err := idl.Marshal([]any{}) - if err != nil { - return nil, err - } var r0 *Account if err := a.a.Query( a.canisterId, "icrc1_minting_account", - args, + []any{}, []any{&r0}, ); err != nil { return nil, err @@ -129,15 +109,11 @@ func (a Agent) Icrc1MintingAccount() (**Account, error) { // Icrc1Name calls the "icrc1_name" method on the "icrc1" canister. func (a Agent) Icrc1Name() (*string, error) { - args, err := idl.Marshal([]any{}) - if err != nil { - return nil, err - } var r0 string if err := a.a.Query( a.canisterId, "icrc1_name", - args, + []any{}, []any{&r0}, ); err != nil { return nil, err @@ -150,10 +126,6 @@ func (a Agent) Icrc1SupportedStandards() (*[]struct { Name string `ic:"name"` Url string `ic:"url"` }, error) { - args, err := idl.Marshal([]any{}) - if err != nil { - return nil, err - } var r0 []struct { Name string `ic:"name"` Url string `ic:"url"` @@ -161,7 +133,7 @@ func (a Agent) Icrc1SupportedStandards() (*[]struct { if err := a.a.Query( a.canisterId, "icrc1_supported_standards", - args, + []any{}, []any{&r0}, ); err != nil { return nil, err @@ -171,15 +143,11 @@ func (a Agent) Icrc1SupportedStandards() (*[]struct { // Icrc1Symbol calls the "icrc1_symbol" method on the "icrc1" canister. func (a Agent) Icrc1Symbol() (*string, error) { - args, err := idl.Marshal([]any{}) - if err != nil { - return nil, err - } var r0 string if err := a.a.Query( a.canisterId, "icrc1_symbol", - args, + []any{}, []any{&r0}, ); err != nil { return nil, err @@ -189,15 +157,11 @@ func (a Agent) Icrc1Symbol() (*string, error) { // Icrc1TotalSupply calls the "icrc1_total_supply" method on the "icrc1" canister. func (a Agent) Icrc1TotalSupply() (*idl.Nat, error) { - args, err := idl.Marshal([]any{}) - if err != nil { - return nil, err - } var r0 idl.Nat if err := a.a.Query( a.canisterId, "icrc1_total_supply", - args, + []any{}, []any{&r0}, ); err != nil { return nil, err @@ -210,10 +174,6 @@ func (a Agent) Icrc1Transfer(arg0 TransferArgs) (*struct { Ok *idl.Nat `ic:"Ok,variant"` Err *TransferError `ic:"Err,variant"` }, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 struct { Ok *idl.Nat `ic:"Ok,variant"` Err *TransferError `ic:"Err,variant"` @@ -221,7 +181,7 @@ func (a Agent) Icrc1Transfer(arg0 TransferArgs) (*struct { if err := a.a.Call( a.canisterId, "icrc1_transfer", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err diff --git a/ic/icrc1/agent_test.go b/ic/icrc1/agent_test.go index 99983a6..38a8a64 100755 --- a/ic/icrc1/agent_test.go +++ b/ic/icrc1/agent_test.go @@ -1,4 +1,4 @@ -// Automatically generated by https://github.com/aviate-labs/agent-go. +// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. package icrc1_test import ( diff --git a/ic/icrc1/types.mo b/ic/icrc1/types.mo new file mode 100755 index 0000000..ec9f702 --- /dev/null +++ b/ic/icrc1/types.mo @@ -0,0 +1,10 @@ +// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. +module T { + public type Timestamp = Nat64; + public type Duration = Nat64; + public type Subaccount = Blob; + public type Account = { owner : Principal; subaccount : ?T.Subaccount }; + public type TransferArgs = { from_subaccount : ?T.Subaccount; to : T.Account; amount : Nat; fee : ?Nat; memo : ?Blob; created_at_time : ?T.Timestamp }; + public type TransferError = { #BadFee : { expected_fee : Nat }; #BadBurn : { min_burn_amount : Nat }; #InsufficientFunds : { balance : Nat }; #TooOld; #CreatedInFuture : { ledger_time : T.Timestamp }; #Duplicate : { duplicate_of : Nat }; #TemporarilyUnavailable; #GenericError : { error_code : Nat; message : Text } }; + public type Value = { #Nat : Nat; #Int : Int; #Text : Text; #Blob : Blob }; +}; diff --git a/ic/testdata/gen.go b/ic/testdata/gen.go index fc8c4e4..182e74c 100644 --- a/ic/testdata/gen.go +++ b/ic/testdata/gen.go @@ -62,6 +62,23 @@ func main() { } _ = os.WriteFile(fmt.Sprintf("%s/agent_test.go", dir), raw, os.ModePerm) } + { + g, err := gen.NewGenerator("", name, name, did) + g.ModulePath = "github.com/aviate-labs/agent-go/ic" + if err != nil { + log.Panic(err) + } + rawTypes, err := g.GenerateActorTypes() + if err != nil { + log.Panic(err) + } + _ = os.WriteFile(fmt.Sprintf("%s/types.mo", dir), rawTypes, os.ModePerm) + rawActor, err := g.GenerateActor() + if err != nil { + log.Panic(err) + } + _ = os.WriteFile(fmt.Sprintf("%s/actor.mo", dir), rawActor, os.ModePerm) + } } } } diff --git a/ic/types_agent_test.go b/ic/types_agent_test.go index f7dc29f..c5b7be6 100755 --- a/ic/types_agent_test.go +++ b/ic/types_agent_test.go @@ -28,16 +28,12 @@ func NewTypesAgent(canisterId principal.Principal, config agent.Config) (*TypesA // Bool calls the "bool" method on the "types" canister. func (a TypesAgent) Bool(arg0 bool, arg1 []bool) (*bool, *[]bool, error) { - args, err := idl.Marshal([]any{arg0, arg1}) - if err != nil { - return nil, nil, err - } var r0 bool var r1 []bool if err := a.a.Call( a.canisterId, "bool", - args, + []any{arg0, arg1}, []any{&r0, &r1}, ); err != nil { return nil, nil, err @@ -47,10 +43,6 @@ func (a TypesAgent) Bool(arg0 bool, arg1 []bool) (*bool, *[]bool, error) { // Float calls the "float" method on the "types" canister. func (a TypesAgent) Float(arg0 float32, arg1 []float32, arg2 float64, arg3 []float64) (*float32, *[]float32, *float64, *[]float64, error) { - args, err := idl.Marshal([]any{arg0, arg1, arg2, arg3}) - if err != nil { - return nil, nil, nil, nil, err - } var r0 float32 var r1 []float32 var r2 float64 @@ -58,7 +50,7 @@ func (a TypesAgent) Float(arg0 float32, arg1 []float32, arg2 float64, arg3 []flo if err := a.a.Call( a.canisterId, "float", - args, + []any{arg0, arg1, arg2, arg3}, []any{&r0, &r1, &r2, &r3}, ); err != nil { return nil, nil, nil, nil, err @@ -68,10 +60,6 @@ func (a TypesAgent) Float(arg0 float32, arg1 []float32, arg2 float64, arg3 []flo // Int calls the "int" method on the "types" canister. func (a TypesAgent) Int(arg0 idl.Int, arg1 int8, arg2 int16, arg3 int32, arg4 int64) (*idl.Int, *int8, *int16, *int32, *int64, error) { - args, err := idl.Marshal([]any{arg0, arg1, arg2, arg3, arg4}) - if err != nil { - return nil, nil, nil, nil, nil, err - } var r0 idl.Int var r1 int8 var r2 int16 @@ -80,7 +68,7 @@ func (a TypesAgent) Int(arg0 idl.Int, arg1 int8, arg2 int16, arg3 int32, arg4 in if err := a.a.Call( a.canisterId, "int", - args, + []any{arg0, arg1, arg2, arg3, arg4}, []any{&r0, &r1, &r2, &r3, &r4}, ); err != nil { return nil, nil, nil, nil, nil, err @@ -90,10 +78,6 @@ func (a TypesAgent) Int(arg0 idl.Int, arg1 int8, arg2 int16, arg3 int32, arg4 in // Nat calls the "nat" method on the "types" canister. func (a TypesAgent) Nat(arg0 idl.Nat, arg1 uint8, arg2 uint16, arg3 uint32, arg4 uint64) (*idl.Nat, *uint8, *uint16, *uint32, *uint64, error) { - args, err := idl.Marshal([]any{arg0, arg1, arg2, arg3, arg4}) - if err != nil { - return nil, nil, nil, nil, nil, err - } var r0 idl.Nat var r1 uint8 var r2 uint16 @@ -102,7 +86,7 @@ func (a TypesAgent) Nat(arg0 idl.Nat, arg1 uint8, arg2 uint16, arg3 uint32, arg4 if err := a.a.Call( a.canisterId, "nat", - args, + []any{arg0, arg1, arg2, arg3, arg4}, []any{&r0, &r1, &r2, &r3, &r4}, ); err != nil { return nil, nil, nil, nil, nil, err @@ -112,16 +96,12 @@ func (a TypesAgent) Nat(arg0 idl.Nat, arg1 uint8, arg2 uint16, arg3 uint32, arg4 // Principal calls the "principal" method on the "types" canister. func (a TypesAgent) Principal(arg0 principal.Principal, arg1 []principal.Principal) (*principal.Principal, *[]principal.Principal, error) { - args, err := idl.Marshal([]any{arg0, arg1}) - if err != nil { - return nil, nil, err - } var r0 principal.Principal var r1 []principal.Principal if err := a.a.Call( a.canisterId, "principal", - args, + []any{arg0, arg1}, []any{&r0, &r1}, ); err != nil { return nil, nil, err @@ -131,16 +111,12 @@ func (a TypesAgent) Principal(arg0 principal.Principal, arg1 []principal.Princip // Text calls the "text" method on the "types" canister. func (a TypesAgent) Text(arg0 string, arg1 []string) (*string, *[]string, error) { - args, err := idl.Marshal([]any{arg0, arg1}) - if err != nil { - return nil, nil, err - } var r0 string var r1 []string if err := a.a.Call( a.canisterId, "text", - args, + []any{arg0, arg1}, []any{&r0, &r1}, ); err != nil { return nil, nil, err @@ -150,10 +126,6 @@ func (a TypesAgent) Text(arg0 string, arg1 []string) (*string, *[]string, error) // VecInt calls the "vec_int" method on the "types" canister. func (a TypesAgent) VecInt(arg0 []idl.Int, arg1 []int8, arg2 []int16, arg3 []int32, arg4 []int64) (*[]idl.Int, *[]int8, *[]int16, *[]int32, *[]int64, error) { - args, err := idl.Marshal([]any{arg0, arg1, arg2, arg3, arg4}) - if err != nil { - return nil, nil, nil, nil, nil, err - } var r0 []idl.Int var r1 []int8 var r2 []int16 @@ -162,7 +134,7 @@ func (a TypesAgent) VecInt(arg0 []idl.Int, arg1 []int8, arg2 []int16, arg3 []int if err := a.a.Call( a.canisterId, "vec_int", - args, + []any{arg0, arg1, arg2, arg3, arg4}, []any{&r0, &r1, &r2, &r3, &r4}, ); err != nil { return nil, nil, nil, nil, nil, err @@ -172,10 +144,6 @@ func (a TypesAgent) VecInt(arg0 []idl.Int, arg1 []int8, arg2 []int16, arg3 []int // VecNat calls the "vec_nat" method on the "types" canister. func (a TypesAgent) VecNat(arg0 []idl.Nat, arg1 []uint8, arg2 []uint16, arg3 []uint32, arg4 []uint64) (*[]idl.Nat, *[]uint8, *[]uint16, *[]uint32, *[]uint64, error) { - args, err := idl.Marshal([]any{arg0, arg1, arg2, arg3, arg4}) - if err != nil { - return nil, nil, nil, nil, nil, err - } var r0 []idl.Nat var r1 []uint8 var r2 []uint16 @@ -184,7 +152,7 @@ func (a TypesAgent) VecNat(arg0 []idl.Nat, arg1 []uint8, arg2 []uint16, arg3 []u if err := a.a.Call( a.canisterId, "vec_nat", - args, + []any{arg0, arg1, arg2, arg3, arg4}, []any{&r0, &r1, &r2, &r3, &r4}, ); err != nil { return nil, nil, nil, nil, nil, err diff --git a/ic/wallet/actor.mo b/ic/wallet/actor.mo new file mode 100755 index 0000000..0f31de4 --- /dev/null +++ b/ic/wallet/actor.mo @@ -0,0 +1,106 @@ +// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. +import T "types"; + +import { principalOfBlob } = "mo:⛔"; + +actor class wallet() : async actor {} { + public query func api_version() : async (Nat16) { + (38652) + }; + public query func get(arg0 : { key : T.Key; accept_encodings : [Text] }) : async ({ content : Blob; content_type : Text; content_encoding : Text; sha256 : ?Blob; total_length : Nat }) { + ({ content = "x287F06984DD27FAABD0E49110AC27F321B5538A4BD8E1D253F8AFFD1A9C81C5B"; content_type = "13842832487040869502"; content_encoding = "9207851698408531338"; sha256 = ?"x7B1BCA3A098396CB5C620BF809689EE32C89B845322F01379CB07CF44C41BFC6"; total_length = 15226500214129345624 }) + }; + public query func get_chunk(arg0 : { key : T.Key; content_encoding : Text; index : Nat; sha256 : ?Blob }) : async ({ content : Blob }) { + ({ content = "x287F06984DD27FAABD0E49110AC27F321B5538A4BD8E1D253F8AFFD1A9C81C5B" }) + }; + public query func list(arg0 : { }) : async ([{ key : T.Key; content_type : Text; encodings : [{ content_encoding : Text; sha256 : ?Blob; length : Nat; modified : T.Time }] }]) { + ([ { key = "7404491806706941354"; content_type = "10285557685837050495"; encodings = [ { content_encoding = "6353661455985592489"; sha256 = ?"x7EE44EF3CD9E1B8A251E9C55DCC87B1BCA3A098396CB5C620BF809689EE32C89"; length = 8643670682807763247; modified = 10342561696286982476 }, { content_encoding = "15226500214129345624"; sha256 = ?"x9614DC1B2711874D3E6FE25E3A8F72C632E3513A5F5E92AF8BF9CEF5969C068E"; length = 9589032066643545779; modified = 5539044620517515997 }, { content_encoding = "1923756884486142631"; sha256 = ?"x1D8C751BCB77BB0746C29470D17024B544336AECB870087656C06A2339BC49BC"; length = 2653383589281119158; modified = 10428971936530044628 }, { content_encoding = "7786994376157721829"; sha256 = ?"x84C261981FA00B16B635580B470ABE60197656644765CA6F5488D5E4A7A530B0"; length = 14150654805229633014; modified = 8157667525784526154 }, { content_encoding = "13234612580036397592"; sha256 = ?"x7A74B6930B2F2C16BB7A5A5071CC53F4577AC3864C4C583CF068857E9B69403F"; length = 2326156757508477903; modified = 13534220423551798816 }, { content_encoding = "17298645943394680105"; sha256 = ?"x1D71DBBBA4BD4FE4384BFDF2965F7F9ED9195ABCD5F15EA919870B1305B6FBEA"; length = 7193462899950823818; modified = 5372797585040004340 } ] }, { key = "8405210950166936129"; content_type = "13851258177473485163"; encodings = [ { content_encoding = "10165017509674453068"; sha256 = ?"x3E35C32D75D3C4784E82EAAF4E3162231C6ED7DC02090A31DDC9A189CA85FAFB"; length = 9076123652376596064; modified = 13788132375959277386 }, { content_encoding = "10818449170260277067"; sha256 = ?"xC0FBF50AE9F93AF1C4CDDD15F8511661030D29CA18CD734D791C7A26999F921C"; length = 15936827406159436595; modified = 1077672755291584990 }, { content_encoding = "16003893191925063214"; sha256 = ?"x3C85ECB90741D9ACC5033E6346556F9DFB82D7E06BDB7DA0FCB214B94F717AD2"; length = 4730893632513896881; modified = 13772962967874715627 }, { content_encoding = "6859593430023241065"; sha256 = ?"x76D889905ABF73E5097448C3AC58856465CC7F7283739F38CCD7E97B29B53311"; length = 14445486139781075996; modified = 9938180212790421664 } ] }, { key = "9101864922507107316"; content_type = "1536328808225679195"; encodings = [ { content_encoding = "13231498797124074758"; sha256 = ?"x94F5F07C5016E89FF5A0DD8105640A16418B9B471476359529B6F56DB15E24BB"; length = 17387340558135946525; modified = 11977568734881657944 } ] }, { key = "8679673755513378830"; content_type = "10491644904757661466"; encodings = [ { content_encoding = "1562262160616910768"; sha256 = ?"x5ACC94A73AF8C7183D527B00A4376396249EB14513AB937A9AC8FCB67AB53FB8"; length = 7727076029448843586; modified = 2343418153347362432 }, { content_encoding = "7201485676058401090"; sha256 = ?"x57331E8D5B453222B9C7CC43D1DC5BBA2095F24CB92AB1930CCAEA0285B7A568"; length = 8789469013259815246; modified = 14122149734664040066 } ] } ]) + }; + public query func certified_tree(arg0 : { }) : async ({ certificate : Blob; tree : Blob }) { + ({ certificate = "x287F06984DD27FAABD0E49110AC27F321B5538A4BD8E1D253F8AFFD1A9C81C5B"; tree = "x7EE44EF3CD9E1B8A251E9C55DCC87B1BCA3A098396CB5C620BF809689EE32C89" }) + }; + public shared func create_batch(arg0 : { }) : async ({ batch_id : T.BatchId }) { + ({ batch_id = 12501942321308663592 }) + }; + public shared func create_chunk(arg0 : { batch_id : T.BatchId; content : Blob }) : async ({ chunk_id : T.ChunkId }) { + ({ chunk_id = 12501942321308663592 }) + }; + public shared func commit_batch(arg0 : T.CommitBatchArguments) : async () { + () + }; + public shared func propose_commit_batch(arg0 : T.CommitBatchArguments) : async () { + () + }; + public shared func commit_proposed_batch(arg0 : T.CommitProposedBatchArguments) : async () { + () + }; + public shared func compute_evidence(arg0 : T.ComputeEvidenceArguments) : async (?Blob) { + (?"x287F06984DD27FAABD0E49110AC27F321B5538A4BD8E1D253F8AFFD1A9C81C5B") + }; + public shared func delete_batch(arg0 : T.DeleteBatchArguments) : async () { + () + }; + public shared func create_asset(arg0 : T.CreateAssetArguments) : async () { + () + }; + public shared func set_asset_content(arg0 : T.SetAssetContentArguments) : async () { + () + }; + public shared func unset_asset_content(arg0 : T.UnsetAssetContentArguments) : async () { + () + }; + public shared func delete_asset(arg0 : T.DeleteAssetArguments) : async () { + () + }; + public shared func clear(arg0 : T.ClearArguments) : async () { + () + }; + public shared func store(arg0 : { key : T.Key; content_type : Text; content_encoding : Text; content : Blob; sha256 : ?Blob }) : async () { + () + }; + public query func http_request(arg0 : T.HttpRequest) : async (T.HttpResponse) { + ({ status_code = 38652; headers = [ ( "10285557685837050495", "16344125491934207374" ), ( "6353661455985592489", "13842832487040869502" ), ( "9207851698408531338", "7031951943849876347" ), ( "10982038652290489547", "12408056582236857246" ) ]; body = "x2F01379CB07CF44C41BFC610298858C4967345654F9614DC1B2711874D3E6FE2"; streaming_strategy = ?#Callback({ callback = { /* func */ }; token = { key = "6194084433703703134"; content_encoding = "4389663725167484054"; index = 9589032066643545779; sha256 = ?"xDD22FC38BCA3DEA73A02A6B18EB21D8C751BCB77BB0746C29470D17024B54433" } }) }) + }; + public query func http_request_streaming_callback(arg0 : T.StreamingCallbackToken) : async (?T.StreamingCallbackHttpResponse) { + (?{ body = "x287F06984DD27FAABD0E49110AC27F321B5538A4BD8E1D253F8AFFD1A9C81C5B"; token = ?{ key = "13842832487040869502"; content_encoding = "9207851698408531338"; index = 7031951943849876347; sha256 = ?"xCB5C620BF809689EE32C89B845322F01379CB07CF44C41BFC610298858C49673" } }) + }; + public shared func authorize(arg0 : Principal) : async () { + () + }; + public shared func deauthorize(arg0 : Principal) : async () { + () + }; + public query func list_authorized() : async ([Principal]) { + ([ principalOfBlob("xAABD0E49110AC27F321B5538A4BD8E1D253F8AFFD1A9C81C5B6EBD2C7EE44EF3"), principalOfBlob("x8A251E9C55DCC87B1BCA3A098396CB5C620BF809689EE32C89B845322F01379C"), principalOfBlob("x4C41BFC610298858C4967345654F9614DC1B2711874D3E6FE25E3A8F72C632E3"), principalOfBlob("x5E92AF8BF9CEF5969C068EE637EBB34E1E18DC1513DD22FC38BCA3DEA73A02A6") ]) + }; + public shared func grant_permission(arg0 : T.GrantPermission) : async () { + () + }; + public shared func revoke_permission(arg0 : T.RevokePermission) : async () { + () + }; + public query func list_permitted(arg0 : T.ListPermitted) : async ([Principal]) { + ([ principalOfBlob("xAABD0E49110AC27F321B5538A4BD8E1D253F8AFFD1A9C81C5B6EBD2C7EE44EF3"), principalOfBlob("x8A251E9C55DCC87B1BCA3A098396CB5C620BF809689EE32C89B845322F01379C"), principalOfBlob("x4C41BFC610298858C4967345654F9614DC1B2711874D3E6FE25E3A8F72C632E3"), principalOfBlob("x5E92AF8BF9CEF5969C068EE637EBB34E1E18DC1513DD22FC38BCA3DEA73A02A6") ]) + }; + public shared func take_ownership() : async () { + () + }; + public query func get_asset_properties(arg0 : T.Key) : async ({ max_age : ?Nat64; headers : ?[T.HeaderField]; allow_raw_access : ?Bool; is_aliased : ?Bool }) { + ({ max_age = ?12501942321308663592; headers = ?[ ( "10285557685837050495", "16344125491934207374" ), ( "6353661455985592489", "13842832487040869502" ), ( "9207851698408531338", "7031951943849876347" ), ( "10982038652290489547", "12408056582236857246" ) ]; allow_raw_access = ?false; is_aliased = ?true }) + }; + public shared func set_asset_properties(arg0 : T.SetAssetPropertiesArguments) : async () { + () + }; + public shared func validate_grant_permission(arg0 : T.GrantPermission) : async (T.ValidationResult) { + (#Ok("7404491806706941354")) + }; + public shared func validate_revoke_permission(arg0 : T.RevokePermission) : async (T.ValidationResult) { + (#Ok("7404491806706941354")) + }; + public shared func validate_take_ownership() : async (T.ValidationResult) { + (#Ok("7404491806706941354")) + }; + public shared func validate_commit_proposed_batch(arg0 : T.CommitProposedBatchArguments) : async (T.ValidationResult) { + (#Ok("7404491806706941354")) + }; +} diff --git a/ic/wallet/agent.go b/ic/wallet/agent.go index a8e2210..c6a2b9a 100755 --- a/ic/wallet/agent.go +++ b/ic/wallet/agent.go @@ -28,15 +28,11 @@ func NewAgent(canisterId principal.Principal, config agent.Config) (*Agent, erro // ApiVersion calls the "api_version" method on the "wallet" canister. func (a Agent) ApiVersion() (*uint16, error) { - args, err := idl.Marshal([]any{}) - if err != nil { - return nil, err - } var r0 uint16 if err := a.a.Query( a.canisterId, "api_version", - args, + []any{}, []any{&r0}, ); err != nil { return nil, err @@ -46,14 +42,10 @@ func (a Agent) ApiVersion() (*uint16, error) { // Authorize calls the "authorize" method on the "wallet" canister. func (a Agent) Authorize(arg0 principal.Principal) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "authorize", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -67,10 +59,6 @@ func (a Agent) CertifiedTree(arg0 struct { Certificate []byte `ic:"certificate"` Tree []byte `ic:"tree"` }, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 struct { Certificate []byte `ic:"certificate"` Tree []byte `ic:"tree"` @@ -78,7 +66,7 @@ func (a Agent) CertifiedTree(arg0 struct { if err := a.a.Query( a.canisterId, "certified_tree", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -88,14 +76,10 @@ func (a Agent) CertifiedTree(arg0 struct { // Clear calls the "clear" method on the "wallet" canister. func (a Agent) Clear(arg0 ClearArguments) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "clear", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -105,14 +89,10 @@ func (a Agent) Clear(arg0 ClearArguments) error { // CommitBatch calls the "commit_batch" method on the "wallet" canister. func (a Agent) CommitBatch(arg0 CommitBatchArguments) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "commit_batch", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -122,14 +102,10 @@ func (a Agent) CommitBatch(arg0 CommitBatchArguments) error { // CommitProposedBatch calls the "commit_proposed_batch" method on the "wallet" canister. func (a Agent) CommitProposedBatch(arg0 CommitProposedBatchArguments) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "commit_proposed_batch", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -139,15 +115,11 @@ func (a Agent) CommitProposedBatch(arg0 CommitProposedBatchArguments) error { // ComputeEvidence calls the "compute_evidence" method on the "wallet" canister. func (a Agent) ComputeEvidence(arg0 ComputeEvidenceArguments) (**[]byte, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 *[]byte if err := a.a.Call( a.canisterId, "compute_evidence", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -157,14 +129,10 @@ func (a Agent) ComputeEvidence(arg0 ComputeEvidenceArguments) (**[]byte, error) // CreateAsset calls the "create_asset" method on the "wallet" canister. func (a Agent) CreateAsset(arg0 CreateAssetArguments) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "create_asset", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -177,17 +145,13 @@ func (a Agent) CreateBatch(arg0 struct { }) (*struct { BatchId BatchId `ic:"batch_id"` }, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 struct { BatchId BatchId `ic:"batch_id"` } if err := a.a.Call( a.canisterId, "create_batch", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -202,17 +166,13 @@ func (a Agent) CreateChunk(arg0 struct { }) (*struct { ChunkId ChunkId `ic:"chunk_id"` }, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 struct { ChunkId ChunkId `ic:"chunk_id"` } if err := a.a.Call( a.canisterId, "create_chunk", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -222,14 +182,10 @@ func (a Agent) CreateChunk(arg0 struct { // Deauthorize calls the "deauthorize" method on the "wallet" canister. func (a Agent) Deauthorize(arg0 principal.Principal) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "deauthorize", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -239,14 +195,10 @@ func (a Agent) Deauthorize(arg0 principal.Principal) error { // DeleteAsset calls the "delete_asset" method on the "wallet" canister. func (a Agent) DeleteAsset(arg0 DeleteAssetArguments) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "delete_asset", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -256,14 +208,10 @@ func (a Agent) DeleteAsset(arg0 DeleteAssetArguments) error { // DeleteBatch calls the "delete_batch" method on the "wallet" canister. func (a Agent) DeleteBatch(arg0 DeleteBatchArguments) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "delete_batch", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -282,10 +230,6 @@ func (a Agent) Get(arg0 struct { Sha256 *[]byte `ic:"sha256,omitempty"` TotalLength idl.Nat `ic:"total_length"` }, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 struct { Content []byte `ic:"content"` ContentType string `ic:"content_type"` @@ -296,7 +240,7 @@ func (a Agent) Get(arg0 struct { if err := a.a.Query( a.canisterId, "get", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -311,10 +255,6 @@ func (a Agent) GetAssetProperties(key Key) (*struct { AllowRawAccess *bool `ic:"allow_raw_access,omitempty"` IsAliased *bool `ic:"is_aliased,omitempty"` }, error) { - args, err := idl.Marshal([]any{key}) - if err != nil { - return nil, err - } var r0 struct { MaxAge *uint64 `ic:"max_age,omitempty"` Headers *[]HeaderField `ic:"headers,omitempty"` @@ -324,7 +264,7 @@ func (a Agent) GetAssetProperties(key Key) (*struct { if err := a.a.Query( a.canisterId, "get_asset_properties", - args, + []any{key}, []any{&r0}, ); err != nil { return nil, err @@ -341,17 +281,13 @@ func (a Agent) GetChunk(arg0 struct { }) (*struct { Content []byte `ic:"content"` }, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 struct { Content []byte `ic:"content"` } if err := a.a.Query( a.canisterId, "get_chunk", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -361,14 +297,10 @@ func (a Agent) GetChunk(arg0 struct { // GrantPermission calls the "grant_permission" method on the "wallet" canister. func (a Agent) GrantPermission(arg0 GrantPermission) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "grant_permission", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -378,15 +310,11 @@ func (a Agent) GrantPermission(arg0 GrantPermission) error { // HttpRequest calls the "http_request" method on the "wallet" canister. func (a Agent) HttpRequest(request HttpRequest) (*HttpResponse, error) { - args, err := idl.Marshal([]any{request}) - if err != nil { - return nil, err - } var r0 HttpResponse if err := a.a.Query( a.canisterId, "http_request", - args, + []any{request}, []any{&r0}, ); err != nil { return nil, err @@ -396,15 +324,11 @@ func (a Agent) HttpRequest(request HttpRequest) (*HttpResponse, error) { // HttpRequestStreamingCallback calls the "http_request_streaming_callback" method on the "wallet" canister. func (a Agent) HttpRequestStreamingCallback(token StreamingCallbackToken) (**StreamingCallbackHttpResponse, error) { - args, err := idl.Marshal([]any{token}) - if err != nil { - return nil, err - } var r0 *StreamingCallbackHttpResponse if err := a.a.Query( a.canisterId, "http_request_streaming_callback", - args, + []any{token}, []any{&r0}, ); err != nil { return nil, err @@ -424,10 +348,6 @@ func (a Agent) List(arg0 struct { Modified Time `ic:"modified"` } `ic:"encodings"` }, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 []struct { Key Key `ic:"key"` ContentType string `ic:"content_type"` @@ -441,7 +361,7 @@ func (a Agent) List(arg0 struct { if err := a.a.Query( a.canisterId, "list", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -451,15 +371,11 @@ func (a Agent) List(arg0 struct { // ListAuthorized calls the "list_authorized" method on the "wallet" canister. func (a Agent) ListAuthorized() (*[]principal.Principal, error) { - args, err := idl.Marshal([]any{}) - if err != nil { - return nil, err - } var r0 []principal.Principal if err := a.a.Query( a.canisterId, "list_authorized", - args, + []any{}, []any{&r0}, ); err != nil { return nil, err @@ -469,15 +385,11 @@ func (a Agent) ListAuthorized() (*[]principal.Principal, error) { // ListPermitted calls the "list_permitted" method on the "wallet" canister. func (a Agent) ListPermitted(arg0 ListPermitted) (*[]principal.Principal, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 []principal.Principal if err := a.a.Query( a.canisterId, "list_permitted", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -487,14 +399,10 @@ func (a Agent) ListPermitted(arg0 ListPermitted) (*[]principal.Principal, error) // ProposeCommitBatch calls the "propose_commit_batch" method on the "wallet" canister. func (a Agent) ProposeCommitBatch(arg0 CommitBatchArguments) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "propose_commit_batch", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -504,14 +412,10 @@ func (a Agent) ProposeCommitBatch(arg0 CommitBatchArguments) error { // RevokePermission calls the "revoke_permission" method on the "wallet" canister. func (a Agent) RevokePermission(arg0 RevokePermission) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "revoke_permission", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -521,14 +425,10 @@ func (a Agent) RevokePermission(arg0 RevokePermission) error { // SetAssetContent calls the "set_asset_content" method on the "wallet" canister. func (a Agent) SetAssetContent(arg0 SetAssetContentArguments) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "set_asset_content", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -538,14 +438,10 @@ func (a Agent) SetAssetContent(arg0 SetAssetContentArguments) error { // SetAssetProperties calls the "set_asset_properties" method on the "wallet" canister. func (a Agent) SetAssetProperties(arg0 SetAssetPropertiesArguments) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "set_asset_properties", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -561,14 +457,10 @@ func (a Agent) Store(arg0 struct { Content []byte `ic:"content"` Sha256 *[]byte `ic:"sha256,omitempty"` }) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "store", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -578,14 +470,10 @@ func (a Agent) Store(arg0 struct { // TakeOwnership calls the "take_ownership" method on the "wallet" canister. func (a Agent) TakeOwnership() error { - args, err := idl.Marshal([]any{}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "take_ownership", - args, + []any{}, []any{}, ); err != nil { return err @@ -595,14 +483,10 @@ func (a Agent) TakeOwnership() error { // UnsetAssetContent calls the "unset_asset_content" method on the "wallet" canister. func (a Agent) UnsetAssetContent(arg0 UnsetAssetContentArguments) error { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return err - } if err := a.a.Call( a.canisterId, "unset_asset_content", - args, + []any{arg0}, []any{}, ); err != nil { return err @@ -612,15 +496,11 @@ func (a Agent) UnsetAssetContent(arg0 UnsetAssetContentArguments) error { // ValidateCommitProposedBatch calls the "validate_commit_proposed_batch" method on the "wallet" canister. func (a Agent) ValidateCommitProposedBatch(arg0 CommitProposedBatchArguments) (*ValidationResult, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 ValidationResult if err := a.a.Call( a.canisterId, "validate_commit_proposed_batch", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -630,15 +510,11 @@ func (a Agent) ValidateCommitProposedBatch(arg0 CommitProposedBatchArguments) (* // ValidateGrantPermission calls the "validate_grant_permission" method on the "wallet" canister. func (a Agent) ValidateGrantPermission(arg0 GrantPermission) (*ValidationResult, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 ValidationResult if err := a.a.Call( a.canisterId, "validate_grant_permission", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -648,15 +524,11 @@ func (a Agent) ValidateGrantPermission(arg0 GrantPermission) (*ValidationResult, // ValidateRevokePermission calls the "validate_revoke_permission" method on the "wallet" canister. func (a Agent) ValidateRevokePermission(arg0 RevokePermission) (*ValidationResult, error) { - args, err := idl.Marshal([]any{arg0}) - if err != nil { - return nil, err - } var r0 ValidationResult if err := a.a.Call( a.canisterId, "validate_revoke_permission", - args, + []any{arg0}, []any{&r0}, ); err != nil { return nil, err @@ -666,15 +538,11 @@ func (a Agent) ValidateRevokePermission(arg0 RevokePermission) (*ValidationResul // ValidateTakeOwnership calls the "validate_take_ownership" method on the "wallet" canister. func (a Agent) ValidateTakeOwnership() (*ValidationResult, error) { - args, err := idl.Marshal([]any{}) - if err != nil { - return nil, err - } var r0 ValidationResult if err := a.a.Call( a.canisterId, "validate_take_ownership", - args, + []any{}, []any{&r0}, ); err != nil { return nil, err diff --git a/ic/wallet/agent_test.go b/ic/wallet/agent_test.go index e91d8a9..c14f1b0 100755 --- a/ic/wallet/agent_test.go +++ b/ic/wallet/agent_test.go @@ -1,4 +1,4 @@ -// Automatically generated by https://github.com/aviate-labs/agent-go. +// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. package wallet_test import ( diff --git a/ic/wallet/types.mo b/ic/wallet/types.mo new file mode 100755 index 0000000..fae4e91 --- /dev/null +++ b/ic/wallet/types.mo @@ -0,0 +1,29 @@ +// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. +module T { + public type BatchId = Nat; + public type ChunkId = Nat; + public type Key = Text; + public type Time = Int; + public type CreateAssetArguments = { key : T.Key; content_type : Text; max_age : ?Nat64; headers : ?[T.HeaderField]; enable_aliasing : ?Bool; allow_raw_access : ?Bool }; + public type SetAssetContentArguments = { key : T.Key; content_encoding : Text; chunk_ids : [T.ChunkId]; sha256 : ?Blob }; + public type UnsetAssetContentArguments = { key : T.Key; content_encoding : Text }; + public type DeleteAssetArguments = { key : T.Key }; + public type ClearArguments = { }; + public type BatchOperationKind = { #CreateAsset : T.CreateAssetArguments; #SetAssetContent : T.SetAssetContentArguments; #SetAssetProperties : T.SetAssetPropertiesArguments; #UnsetAssetContent : T.UnsetAssetContentArguments; #DeleteAsset : T.DeleteAssetArguments; #Clear : T.ClearArguments }; + public type CommitBatchArguments = { batch_id : T.BatchId; operations : [T.BatchOperationKind] }; + public type CommitProposedBatchArguments = { batch_id : T.BatchId; evidence : Blob }; + public type ComputeEvidenceArguments = { batch_id : T.BatchId; max_iterations : ?Nat16 }; + public type DeleteBatchArguments = { batch_id : T.BatchId }; + public type HeaderField = (Text, Text); + public type HttpRequest = { method : Text; url : Text; headers : [T.HeaderField]; body : Blob; certificate_version : ?Nat16 }; + public type HttpResponse = { status_code : Nat16; headers : [T.HeaderField]; body : Blob; streaming_strategy : ?T.StreamingStrategy }; + public type StreamingCallbackHttpResponse = { body : Blob; token : ?T.StreamingCallbackToken }; + public type StreamingCallbackToken = { key : T.Key; content_encoding : Text; index : Nat; sha256 : ?Blob }; + public type StreamingStrategy = { #Callback : { callback : { /* func */ }; token : T.StreamingCallbackToken } }; + public type SetAssetPropertiesArguments = { key : T.Key; max_age : ??Nat64; headers : ??[T.HeaderField]; allow_raw_access : ??Bool; is_aliased : ??Bool }; + public type Permission = { #Commit; #ManagePermissions; #Prepare }; + public type GrantPermission = { to_principal : Principal; permission : T.Permission }; + public type RevokePermission = { of_principal : Principal; permission : T.Permission }; + public type ListPermitted = { permission : T.Permission }; + public type ValidationResult = { #Ok : Text; #Err : Text }; +}; diff --git a/principal/accountid.go b/principal/accountid.go index 595d2ca..e618a85 100644 --- a/principal/accountid.go +++ b/principal/accountid.go @@ -20,6 +20,24 @@ type ( SubAccount [32]byte ) +// DecodeAccountID decodes the given string into an account identifier. +func DecodeAccountID(s string) (AccountIdentifier, error) { + b, err := hex.DecodeString(s) + if err != nil { + return AccountIdentifier{}, err + } + if len(b) != 32 { + return AccountIdentifier{}, fmt.Errorf("invalid length: %d", len(b)) + } + crc := binary.BigEndian.Uint32(b[:4]) + if crc != crc32.ChecksumIEEE(b[4:]) { + return AccountIdentifier{}, fmt.Errorf("invalid checksum: %d", crc) + } + var id AccountIdentifier + copy(id[:], b[4:]) + return id, nil +} + // NewAccountID returns the account identifier corresponding with the given sub-account. func NewAccountID(p Principal, subAccount [32]byte) AccountIdentifier { h := sha256.New224() @@ -40,24 +58,6 @@ func (id AccountIdentifier) Bytes() []byte { return append(crc, id[:]...) } -// DecodeAccountID decodes the given string into an account identifier. -func DecodeAccountID(s string) (AccountIdentifier, error) { - b, err := hex.DecodeString(s) - if err != nil { - return AccountIdentifier{}, err - } - if len(b) != 32 { - return AccountIdentifier{}, fmt.Errorf("invalid length: %d", len(b)) - } - crc := binary.BigEndian.Uint32(b[:4]) - if crc != crc32.ChecksumIEEE(b[4:]) { - return AccountIdentifier{}, fmt.Errorf("invalid checksum: %d", crc) - } - var id AccountIdentifier - copy(id[:], b[4:]) - return id, nil -} - // Encode returns the hexadecimal representation of the account identifier. func (id AccountIdentifier) Encode() string { return hex.EncodeToString(id.Bytes()) diff --git a/principal/icrc/account_test.go b/principal/icrc/account_test.go index 2779ab0..d6466c1 100644 --- a/principal/icrc/account_test.go +++ b/principal/icrc/account_test.go @@ -21,6 +21,22 @@ func ExampleAccount() { // k2t6j-2nvnp-4zjm3-25dtz-6xhaa-c7boj-5gayf-oj3xs-i43lp-teztq-6ae-dfxgiyy.102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20 } +func TestAccountIdentifier(t *testing.T) { + for i := 0; i < 100; i++ { + a := icrc.Account{ + Owner: principal.Principal{}, + SubAccount: &[32]byte{byte(i)}, + } + accountID, err := icrc.Decode(a.String()) + if err != nil { + t.Error(err) + } + if accountID.String() != a.String() { + t.Errorf("expected %s, got %s", a.String(), accountID.String()) + } + } +} + func TestVectors(t *testing.T) { for _, test := range []struct { account string @@ -46,19 +62,3 @@ func TestVectors(t *testing.T) { } } } - -func TestAccountIdentifier(t *testing.T) { - for i := 0; i < 100; i++ { - a := icrc.Account{ - Owner: principal.Principal{}, - SubAccount: &[32]byte{byte(i)}, - } - accountID, err := icrc.Decode(a.String()) - if err != nil { - t.Error(err) - } - if accountID.String() != a.String() { - t.Errorf("expected %s, got %s", a.String(), accountID.String()) - } - } -}