diff --git a/Makefile b/Makefile index 1bbe377..9a6195f 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ test-cover: gen: cd candid && go generate cd pocketic && go generate - cd registry && go generate + cd clients/registry && go generate gen-ic: go run ic/testdata/gen.go diff --git a/agent.go b/agent.go index c596b67..b9f2e7a 100644 --- a/agent.go +++ b/agent.go @@ -1,11 +1,13 @@ package agent import ( + "context" "crypto/rand" "encoding/binary" "encoding/hex" "errors" "fmt" + "github.com/aviate-labs/agent-go/candid/idl" "net/url" "reflect" "time" @@ -89,9 +91,66 @@ func uint64FromBytes(raw []byte) uint64 { } } +type APIRequest[In, Out any] struct { + a *Agent + unmarshal func([]byte, Out) error + typ RequestType + methodName string + effectiveCanisterID principal.Principal + requestID RequestID + data []byte +} + +func CreateAPIRequest[In, Out any]( + a *Agent, + marshal func(In) ([]byte, error), + unmarshal func([]byte, Out) error, + typ RequestType, + canisterID principal.Principal, + methodName string, + in In, +) (*APIRequest[In, Out], error) { + rawArgs, err := marshal(in) + if err != nil { + return nil, err + } + nonce, err := newNonce() + if err != nil { + return nil, err + } + requestID, data, err := a.sign(Request{ + Type: typ, + Sender: a.Sender(), + CanisterID: canisterID, + MethodName: methodName, + Arguments: rawArgs, + IngressExpiry: a.expiryDate(), + Nonce: nonce, + }) + if err != nil { + return nil, err + } + return &APIRequest[In, Out]{ + a: a, + unmarshal: unmarshal, + typ: typ, + methodName: methodName, + effectiveCanisterID: canisterID, + requestID: *requestID, + data: data, + }, nil +} + +// WithEffectiveCanisterID sets the effective canister ID for the Call. +func (c *APIRequest[In, Out]) WithEffectiveCanisterID(canisterID principal.Principal) *APIRequest[In, Out] { + c.effectiveCanisterID = canisterID + return c +} + // Agent is a client for the Internet Computer. type Agent struct { client Client + ctx context.Context identity identity.Identity ingressExpiry time.Duration rootKey []byte @@ -103,7 +162,7 @@ type Agent struct { // New returns a new Agent based on the given configuration. func New(cfg Config) (*Agent, error) { if cfg.IngressExpiry == 0 { - cfg.IngressExpiry = time.Minute + cfg.IngressExpiry = 5 * time.Minute } // By default, use the anonymous identity. var id identity.Identity = new(identity.AnonymousIdentity) @@ -139,6 +198,7 @@ func New(cfg Config) (*Agent, error) { } return &Agent{ client: client, + ctx: context.Background(), identity: id, ingressExpiry: cfg.IngressExpiry, rootKey: rootKey, @@ -154,6 +214,19 @@ func (a Agent) Client() *Client { return &a.client } +// CreateCandidAPIRequest creates a new api request to the given canister and method. +func (a *Agent) CreateCandidAPIRequest(typ RequestType, canisterID principal.Principal, methodName string, args ...any) (*CandidAPIRequest, error) { + return CreateAPIRequest[[]any, []any]( + a, + idl.Marshal, + idl.Unmarshal, + typ, + effectiveCanisterID(canisterID, args), + methodName, + args, + ) +} + // GetCanisterControllers returns the list of principals that can control the given canister. func (a Agent) GetCanisterControllers(canisterID principal.Principal) ([]principal.Principal, error) { resp, err := a.GetCanisterInfo(canisterID, "controllers") @@ -252,7 +325,9 @@ func (a Agent) Sender() principal.Principal { } func (a Agent) call(ecID principal.Principal, data []byte) ([]byte, error) { - return a.client.Call(ecID, data) + ctx, cancel := context.WithTimeout(a.ctx, a.ingressExpiry) + defer cancel() + return a.client.Call(ctx, ecID, data) } func (a Agent) expiryDate() uint64 { @@ -299,7 +374,9 @@ func (a Agent) poll(ecID principal.Principal, requestID RequestID) ([]byte, erro } func (a Agent) readState(ecID principal.Principal, data []byte) (map[string][]byte, error) { - resp, err := a.client.ReadState(ecID, data) + ctx, cancel := context.WithTimeout(a.ctx, a.ingressExpiry) + defer cancel() + resp, err := a.client.ReadState(ctx, ecID, data) if err != nil { return nil, err } @@ -336,7 +413,9 @@ func (a Agent) readStateCertificate(ecID principal.Principal, paths [][]hashtree } func (a Agent) readSubnetState(subnetID principal.Principal, data []byte) (map[string][]byte, error) { - resp, err := a.client.ReadSubnetState(subnetID, data) + ctx, cancel := context.WithTimeout(a.ctx, a.ingressExpiry) + defer cancel() + resp, err := a.client.ReadSubnetState(ctx, subnetID, data) if err != nil { return nil, err } @@ -385,12 +464,14 @@ func (a Agent) sign(request Request) (*RequestID, []byte, error) { return &requestID, data, nil } +type CandidAPIRequest = APIRequest[[]any, []any] + // Config is the configuration for an Agent. type Config struct { // Identity is the identity used by the Agent. Identity identity.Identity // IngressExpiry is the duration for which an ingress message is valid. - // The default is set to 1 minute. + // The default is set to 5 minutes. IngressExpiry time.Duration // ClientConfig is the configuration for the underlying Client. ClientConfig *ClientConfig diff --git a/call.go b/call.go index 6d4ab34..7e8c4b0 100644 --- a/call.go +++ b/call.go @@ -1,18 +1,41 @@ package agent import ( - "github.com/aviate-labs/agent-go/candid/idl" "github.com/aviate-labs/agent-go/principal" "google.golang.org/protobuf/proto" ) +// Call calls a method on a canister, it does not wait for the result. +func (c APIRequest[_, _]) Call() error { + c.a.logger.Printf("[AGENT] CALL %s %s (%x)", c.effectiveCanisterID, c.methodName, c.requestID) + _, err := c.a.call(c.effectiveCanisterID, c.data) + return err +} + +// CallAndWait calls a method on a canister and waits for the result. +func (c APIRequest[_, Out]) CallAndWait(out Out) error { + if err := c.Call(); err != nil { + return err + } + return c.Wait(out) +} + +// Wait waits for the result of the Call and unmarshals it into the given values. +func (c APIRequest[_, Out]) Wait(out Out) error { + raw, err := c.a.poll(c.effectiveCanisterID, c.requestID) + if err != nil { + return err + } + return c.unmarshal(raw, out) +} + // 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 []any, values []any) error { - call, err := a.CreateCall(canisterID, methodName, args...) +func (a Agent) Call(canisterID principal.Principal, methodName string, in []any, out []any) error { + call, err := a.CreateCandidAPIRequest(RequestTypeCall, canisterID, methodName, in...) if err != nil { return err } - return call.CallAndWait(values...) + return call.CallAndWait(out) } // CallProto calls a method on a canister and unmarshals the result into the given proto message. @@ -41,77 +64,3 @@ func (a Agent) CallProto(canisterID principal.Principal, methodName string, in, } return proto.Unmarshal(raw, out) } - -// CreateCall creates a new Call to the given canister and method. -func (a *Agent) CreateCall(canisterID principal.Principal, methodName string, args ...any) (*Call, error) { - rawArgs, err := idl.Marshal(args) - if err != nil { - return nil, err - } - if len(args) == 0 { - // Default to the empty Candid argument list. - rawArgs = []byte{'D', 'I', 'D', 'L', 0, 0} - } - nonce, err := newNonce() - if err != nil { - return nil, err - } - requestID, data, err := a.sign(Request{ - Type: RequestTypeCall, - Sender: a.Sender(), - CanisterID: canisterID, - MethodName: methodName, - Arguments: rawArgs, - IngressExpiry: a.expiryDate(), - Nonce: nonce, - }) - if err != nil { - return nil, err - } - return &Call{ - a: a, - methodName: methodName, - effectiveCanisterID: effectiveCanisterID(canisterID, args), - requestID: *requestID, - data: data, - }, nil -} - -// Call is an intermediate representation of a Call to a canister. -type Call struct { - a *Agent - methodName string - effectiveCanisterID principal.Principal - requestID RequestID - data []byte -} - -// Call calls a method on a canister, it does not wait for the result. -func (c Call) Call() error { - c.a.logger.Printf("[AGENT] CALL %s %s (%x)", c.effectiveCanisterID, c.methodName, c.requestID) - _, err := c.a.call(c.effectiveCanisterID, c.data) - return err -} - -// CallAndWait calls a method on a canister and waits for the result. -func (c Call) CallAndWait(values ...any) error { - if err := c.Call(); err != nil { - return err - } - return c.Wait(values...) -} - -// Wait waits for the result of the Call and unmarshals it into the given values. -func (c Call) Wait(values ...any) error { - raw, err := c.a.poll(c.effectiveCanisterID, c.requestID) - if err != nil { - return err - } - return idl.Unmarshal(raw, values) -} - -// WithEffectiveCanisterID sets the effective canister ID for the Call. -func (c *Call) WithEffectiveCanisterID(canisterID principal.Principal) *Call { - c.effectiveCanisterID = canisterID - return c -} diff --git a/client.go b/client.go index b45e57b..ffedc4b 100644 --- a/client.go +++ b/client.go @@ -2,6 +2,7 @@ package agent import ( "bytes" + "context" "fmt" "io" "net/http" @@ -40,10 +41,14 @@ func NewClientWithLogger(cfg ClientConfig, logger Logger) Client { } } -func (c Client) Call(canisterID principal.Principal, data []byte) ([]byte, error) { +func (c Client) Call(ctx context.Context, canisterID principal.Principal, data []byte) ([]byte, error) { u := c.url(fmt.Sprintf("/api/v2/canister/%s/call", canisterID.Encode())) c.logger.Printf("[CLIENT] CALL %s", u) - resp, err := c.client.Post(u, "application/cbor", bytes.NewBuffer(data)) + req, err := c.newRequest(ctx, "POST", u, bytes.NewBuffer(data)) + if err != nil { + return nil, err + } + resp, err := c.client.Do(req) if err != nil { return nil, err } @@ -63,16 +68,16 @@ func (c Client) Call(canisterID principal.Principal, data []byte) ([]byte, error } } -func (c Client) Query(canisterID principal.Principal, data []byte) ([]byte, error) { - return c.post("query", canisterID, data) +func (c Client) Query(ctx context.Context, canisterID principal.Principal, data []byte) ([]byte, error) { + return c.post(ctx, "query", canisterID, data) } -func (c Client) ReadState(canisterID principal.Principal, data []byte) ([]byte, error) { - return c.post("read_state", canisterID, data) +func (c Client) ReadState(ctx context.Context, canisterID principal.Principal, data []byte) ([]byte, error) { + return c.post(ctx, "read_state", canisterID, data) } -func (c Client) ReadSubnetState(subnetID principal.Principal, data []byte) ([]byte, error) { - return c.postSubnet("read_state", subnetID, data) +func (c Client) ReadSubnetState(ctx context.Context, subnetID principal.Principal, data []byte) ([]byte, error) { + return c.postSubnet(ctx, "read_state", subnetID, data) } // Status returns the status of the IC. @@ -94,10 +99,23 @@ func (c Client) get(path string) ([]byte, error) { return io.ReadAll(resp.Body) } -func (c Client) post(path string, canisterID principal.Principal, data []byte) ([]byte, error) { +func (c Client) newRequest(ctx context.Context, method, url string, body io.Reader) (*http.Request, error) { + req, err := http.NewRequestWithContext(ctx, method, url, body) + if err != nil { + return nil, err + } + req.Header.Set("Content-Type", "application/cbor") + return req, nil +} + +func (c Client) post(ctx context.Context, path string, canisterID principal.Principal, data []byte) ([]byte, error) { u := c.url(fmt.Sprintf("/api/v2/canister/%s/%s", canisterID.Encode(), path)) c.logger.Printf("[CLIENT] POST %s", u) - resp, err := c.client.Post(u, "application/cbor", bytes.NewBuffer(data)) + req, err := c.newRequest(ctx, "POST", u, bytes.NewBuffer(data)) + if err != nil { + return nil, err + } + resp, err := c.client.Do(req) if err != nil { return nil, err } @@ -110,10 +128,14 @@ func (c Client) post(path string, canisterID principal.Principal, data []byte) ( } } -func (c Client) postSubnet(path string, subnetID principal.Principal, data []byte) ([]byte, error) { +func (c Client) postSubnet(ctx context.Context, path string, subnetID principal.Principal, data []byte) ([]byte, error) { u := c.url(fmt.Sprintf("/api/v2/subnet/%s/%s", subnetID.Encode(), path)) c.logger.Printf("[CLIENT] POST %s", u) - resp, err := c.client.Post(u, "application/cbor", bytes.NewBuffer(data)) + req, err := c.newRequest(ctx, "POST", u, bytes.NewBuffer(data)) + if err != nil { + return nil, err + } + resp, err := c.client.Do(req) if err != nil { return nil, err } diff --git a/clients/ledger/client.go b/clients/ledger/client.go new file mode 100644 index 0000000..d190348 --- /dev/null +++ b/clients/ledger/client.go @@ -0,0 +1 @@ +package ledger diff --git a/registry/README.md b/clients/registry/README.md similarity index 100% rename from registry/README.md rename to clients/registry/README.md diff --git a/registry/client.go b/clients/registry/client.go similarity index 99% rename from registry/client.go rename to clients/registry/client.go index c2591b5..f81dfe2 100644 --- a/registry/client.go +++ b/clients/registry/client.go @@ -3,8 +3,8 @@ package registry import ( "fmt" "github.com/aviate-labs/agent-go/certification" + v1 "github.com/aviate-labs/agent-go/clients/registry/proto/v1" "github.com/aviate-labs/agent-go/principal" - v1 "github.com/aviate-labs/agent-go/registry/proto/v1" "google.golang.org/protobuf/proto" "strings" ) diff --git a/registry/client_test.go b/clients/registry/client_test.go similarity index 91% rename from registry/client_test.go rename to clients/registry/client_test.go index 61c0129..f2c3685 100644 --- a/registry/client_test.go +++ b/clients/registry/client_test.go @@ -1,7 +1,7 @@ package registry_test import ( - "github.com/aviate-labs/agent-go/registry" + "github.com/aviate-labs/agent-go/clients/registry" "os" "testing" ) diff --git a/registry/dataprovider.go b/clients/registry/dataprovider.go similarity index 98% rename from registry/dataprovider.go rename to clients/registry/dataprovider.go index 2a01c4a..89eb96e 100644 --- a/registry/dataprovider.go +++ b/clients/registry/dataprovider.go @@ -7,8 +7,8 @@ import ( "github.com/aviate-labs/agent-go" "github.com/aviate-labs/agent-go/certification" "github.com/aviate-labs/agent-go/certification/hashtree" + "github.com/aviate-labs/agent-go/clients/registry/proto/v1" "github.com/aviate-labs/agent-go/ic" - "github.com/aviate-labs/agent-go/registry/proto/v1" "github.com/aviate-labs/leb128" "github.com/fxamacker/cbor/v2" "google.golang.org/protobuf/proto" diff --git a/registry/dataprovider_test.go b/clients/registry/dataprovider_test.go similarity index 83% rename from registry/dataprovider_test.go rename to clients/registry/dataprovider_test.go index 98031e5..2a4da23 100644 --- a/registry/dataprovider_test.go +++ b/clients/registry/dataprovider_test.go @@ -1,7 +1,7 @@ package registry_test import ( - "github.com/aviate-labs/agent-go/registry" + "github.com/aviate-labs/agent-go/clients/registry" "testing" ) diff --git a/registry/hashtree.go b/clients/registry/hashtree.go similarity index 94% rename from registry/hashtree.go rename to clients/registry/hashtree.go index cc2337e..84ac231 100644 --- a/registry/hashtree.go +++ b/clients/registry/hashtree.go @@ -3,7 +3,7 @@ package registry import ( "fmt" "github.com/aviate-labs/agent-go/certification/hashtree" - v1 "github.com/aviate-labs/agent-go/registry/proto/v1" + v1 "github.com/aviate-labs/agent-go/clients/registry/proto/v1" ) func NewHashTree(tree *v1.MixedHashTree) (*hashtree.HashTree, error) { diff --git a/registry/proto.go b/clients/registry/proto.go similarity index 100% rename from registry/proto.go rename to clients/registry/proto.go diff --git a/registry/proto/v1/local.pb.go b/clients/registry/proto/v1/local.pb.go similarity index 97% rename from registry/proto/v1/local.pb.go rename to clients/registry/proto/v1/local.pb.go index 5de8427..db16176 100644 --- a/registry/proto/v1/local.pb.go +++ b/clients/registry/proto/v1/local.pb.go @@ -2,8 +2,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.34.1 -// protoc v5.26.1 +// protoc-gen-go v1.34.2 +// protoc v5.27.0 // source: local.proto package v1 @@ -56,7 +56,7 @@ var file_local_proto_depIdxs = []int32{ var file_local_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_local_proto_goTypes = []interface{}{ +var file_local_proto_goTypes = []any{ (MutationType)(0), // 0: ic_registry_common.pb.local_store.v1.MutationType (*ChangelogEntry)(nil), // 1: ic_registry_common.pb.local_store.v1.ChangelogEntry (*KeyMutation)(nil), // 2: ic_registry_common.pb.local_store.v1.KeyMutation @@ -375,7 +375,7 @@ func file_local_proto_init() { return } if !protoimpl.UnsafeEnabled { - file_local_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_local_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*ChangelogEntry); i { case 0: return &v.state @@ -387,7 +387,7 @@ func file_local_proto_init() { return nil } } - file_local_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_local_proto_msgTypes[1].Exporter = func(v any, i int) any { switch v := v.(*KeyMutation); i { case 0: return &v.state @@ -399,7 +399,7 @@ func file_local_proto_init() { return nil } } - file_local_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + file_local_proto_msgTypes[2].Exporter = func(v any, i int) any { switch v := v.(*CertifiedTime); i { case 0: return &v.state @@ -411,7 +411,7 @@ func file_local_proto_init() { return nil } } - file_local_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + file_local_proto_msgTypes[3].Exporter = func(v any, i int) any { switch v := v.(*Delta); i { case 0: return &v.state diff --git a/registry/proto/v1/node.pb.go b/clients/registry/proto/v1/node.pb.go similarity index 97% rename from registry/proto/v1/node.pb.go rename to clients/registry/proto/v1/node.pb.go index 0d9fc22..c7bbc1f 100644 --- a/registry/proto/v1/node.pb.go +++ b/clients/registry/proto/v1/node.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.34.1 -// protoc v5.26.1 +// protoc-gen-go v1.34.2 +// protoc v5.27.0 // source: node.proto package v1 @@ -38,7 +38,7 @@ var file_node_proto_depIdxs = []int32{ 0, // [0:3] is the sub-list for field type_name } -var file_node_proto_goTypes = []interface{}{ +var file_node_proto_goTypes = []any{ (*ConnectionEndpoint)(nil), // 0: registry.node.v1.ConnectionEndpoint (*IPv4InterfaceConfig)(nil), // 1: registry.node.v1.IPv4InterfaceConfig (*NodeRecord)(nil), // 2: registry.node.v1.NodeRecord @@ -115,7 +115,7 @@ func file_node_proto_init() { return } if !protoimpl.UnsafeEnabled { - file_node_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_node_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*ConnectionEndpoint); i { case 0: return &v.state @@ -127,7 +127,7 @@ func file_node_proto_init() { return nil } } - file_node_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_node_proto_msgTypes[1].Exporter = func(v any, i int) any { switch v := v.(*IPv4InterfaceConfig); i { case 0: return &v.state @@ -139,7 +139,7 @@ func file_node_proto_init() { return nil } } - file_node_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + file_node_proto_msgTypes[2].Exporter = func(v any, i int) any { switch v := v.(*NodeRecord); i { case 0: return &v.state @@ -152,7 +152,7 @@ func file_node_proto_init() { } } } - file_node_proto_msgTypes[2].OneofWrappers = []interface{}{} + file_node_proto_msgTypes[2].OneofWrappers = []any{} type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ @@ -180,8 +180,6 @@ func file_node_proto_rawDescGZIP() []byte { return file_node_proto_rawDescData } -func init() { file_node_proto_init() } - // A connection endpoint. type ConnectionEndpoint struct { state protoimpl.MessageState @@ -384,6 +382,7 @@ func (x *NodeRecord) GetXnet() *ConnectionEndpoint { } return nil } + func (*NodeRecord) ProtoMessage() {} func (x *NodeRecord) ProtoReflect() protoreflect.Message { mi := &file_node_proto_msgTypes[2] @@ -396,7 +395,6 @@ func (x *NodeRecord) ProtoReflect() protoreflect.Message { } return mi.MessageOf(x) } - func (x *NodeRecord) Reset() { *x = NodeRecord{} if protoimpl.UnsafeEnabled { @@ -405,6 +403,8 @@ func (x *NodeRecord) Reset() { ms.StoreMessageInfo(mi) } } + func (x *NodeRecord) String() string { return protoimpl.X.MessageStringOf(x) } +func init() { file_node_proto_init() } diff --git a/registry/proto/v1/operator.pb.go b/clients/registry/proto/v1/operator.pb.go similarity index 97% rename from registry/proto/v1/operator.pb.go rename to clients/registry/proto/v1/operator.pb.go index 13a63a9..0a3e7aa 100644 --- a/registry/proto/v1/operator.pb.go +++ b/clients/registry/proto/v1/operator.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.34.1 -// protoc v5.26.1 +// protoc-gen-go v1.34.2 +// protoc v5.27.0 // source: operator.proto package v1 @@ -36,7 +36,7 @@ var file_operator_proto_depIdxs = []int32{ 0, // [0:1] is the sub-list for field type_name } -var file_operator_proto_goTypes = []interface{}{ +var file_operator_proto_goTypes = []any{ (*NodeOperatorRecord)(nil), // 0: registry.node_operator.v1.NodeOperatorRecord (*RemoveNodeOperatorsPayload)(nil), // 1: registry.node_operator.v1.RemoveNodeOperatorsPayload nil, // 2: registry.node_operator.v1.NodeOperatorRecord.RewardableNodesEntry @@ -244,7 +244,7 @@ func file_operator_proto_init() { return } if !protoimpl.UnsafeEnabled { - file_operator_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_operator_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*NodeOperatorRecord); i { case 0: return &v.state @@ -256,7 +256,7 @@ func file_operator_proto_init() { return nil } } - file_operator_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_operator_proto_msgTypes[1].Exporter = func(v any, i int) any { switch v := v.(*RemoveNodeOperatorsPayload); i { case 0: return &v.state @@ -269,7 +269,7 @@ func file_operator_proto_init() { } } } - file_operator_proto_msgTypes[0].OneofWrappers = []interface{}{} + file_operator_proto_msgTypes[0].OneofWrappers = []any{} type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ diff --git a/registry/proto/v1/registry.pb.go b/clients/registry/proto/v1/registry.pb.go similarity index 96% rename from registry/proto/v1/registry.pb.go rename to clients/registry/proto/v1/registry.pb.go index 99341d5..7eb79f0 100644 --- a/registry/proto/v1/registry.pb.go +++ b/clients/registry/proto/v1/registry.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.34.1 -// protoc v5.26.1 +// protoc-gen-go v1.34.2 +// protoc v5.27.0 // source: registry.proto package v1 @@ -38,7 +38,7 @@ var file_registry_proto_depIdxs = []int32{ 0, // [0:2] is the sub-list for field type_name } -var file_registry_proto_goTypes = []interface{}{ +var file_registry_proto_goTypes = []any{ (*ProtoRegistry)(nil), // 0: ic_registry_common.pb.proto_registry.v1.ProtoRegistry (*ProtoRegistryRecord)(nil), // 1: ic_registry_common.pb.proto_registry.v1.ProtoRegistryRecord (*wrapperspb.BytesValue)(nil), // 2: google.protobuf.BytesValue @@ -191,7 +191,7 @@ func file_registry_proto_init() { return } if !protoimpl.UnsafeEnabled { - file_registry_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_registry_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*ProtoRegistry); i { case 0: return &v.state @@ -203,7 +203,7 @@ func file_registry_proto_init() { return nil } } - file_registry_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_registry_proto_msgTypes[1].Exporter = func(v any, i int) any { switch v := v.(*ProtoRegistryRecord); i { case 0: return &v.state diff --git a/registry/proto/v1/subnet.pb.go b/clients/registry/proto/v1/subnet.pb.go similarity index 98% rename from registry/proto/v1/subnet.pb.go rename to clients/registry/proto/v1/subnet.pb.go index 0b67deb..398a73e 100644 --- a/registry/proto/v1/subnet.pb.go +++ b/clients/registry/proto/v1/subnet.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.34.1 -// protoc v5.26.1 +// protoc-gen-go v1.34.2 +// protoc v5.27.0 // source: subnet.proto package v1 @@ -214,7 +214,7 @@ var file_subnet_proto_depIdxs = []int32{ var file_subnet_proto_enumTypes = make([]protoimpl.EnumInfo, 6) -var file_subnet_proto_goTypes = []interface{}{ +var file_subnet_proto_goTypes = []any{ (EcdsaCurve)(0), // 0: registry.subnet.v1.EcdsaCurve (NiDkgTag)(0), // 1: registry.subnet.v1.NiDkgTag (AlgorithmId)(0), // 2: registry.subnet.v1.AlgorithmId @@ -3403,7 +3403,6 @@ func (x *VerifiedIDkgDealing) Reset() { func (x *VerifiedIDkgDealing) String() string { return protoimpl.X.MessageStringOf(x) } - type isMasterPublicKeyId_KeyId interface { isMasterPublicKeyId_KeyId() } @@ -3414,7 +3413,7 @@ func file_subnet_proto_init() { return } if !protoimpl.UnsafeEnabled { - file_subnet_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*SubnetRecord); i { case 0: return &v.state @@ -3426,7 +3425,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[1].Exporter = func(v any, i int) any { switch v := v.(*EcdsaKeyId); i { case 0: return &v.state @@ -3438,7 +3437,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[2].Exporter = func(v any, i int) any { switch v := v.(*EcdsaInitialization); i { case 0: return &v.state @@ -3450,7 +3449,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[3].Exporter = func(v any, i int) any { switch v := v.(*CatchUpPackageContents); i { case 0: return &v.state @@ -3462,7 +3461,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[4].Exporter = func(v any, i int) any { switch v := v.(*RegistryStoreUri); i { case 0: return &v.state @@ -3474,7 +3473,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[5].Exporter = func(v any, i int) any { switch v := v.(*SubnetListRecord); i { case 0: return &v.state @@ -3486,7 +3485,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[6].Exporter = func(v any, i int) any { switch v := v.(*NiDkgId); i { case 0: return &v.state @@ -3498,7 +3497,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[7].Exporter = func(v any, i int) any { switch v := v.(*InitialNiDkgTranscriptRecord); i { case 0: return &v.state @@ -3510,7 +3509,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[8].Exporter = func(v any, i int) any { switch v := v.(*PrincipalId); i { case 0: return &v.state @@ -3522,7 +3521,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[9].Exporter = func(v any, i int) any { switch v := v.(*SubnetId); i { case 0: return &v.state @@ -3534,7 +3533,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[10].Exporter = func(v any, i int) any { switch v := v.(*IDkgTranscriptId); i { case 0: return &v.state @@ -3546,7 +3545,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[11].Exporter = func(v any, i int) any { switch v := v.(*VerifiedIDkgDealing); i { case 0: return &v.state @@ -3558,7 +3557,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[12].Exporter = func(v any, i int) any { switch v := v.(*NodeId); i { case 0: return &v.state @@ -3570,7 +3569,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[13].Exporter = func(v any, i int) any { switch v := v.(*PublicKey); i { case 0: return &v.state @@ -3582,7 +3581,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[14].Exporter = func(v any, i int) any { switch v := v.(*IDkgTranscript); i { case 0: return &v.state @@ -3594,7 +3593,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[15].Exporter = func(v any, i int) any { switch v := v.(*DealerTuple); i { case 0: return &v.state @@ -3606,7 +3605,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[16].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[16].Exporter = func(v any, i int) any { switch v := v.(*SignatureTuple); i { case 0: return &v.state @@ -3618,7 +3617,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[17].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[17].Exporter = func(v any, i int) any { switch v := v.(*IDkgTranscriptParams); i { case 0: return &v.state @@ -3630,7 +3629,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[18].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[18].Exporter = func(v any, i int) any { switch v := v.(*IDkgDealing); i { case 0: return &v.state @@ -3642,7 +3641,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[19].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[19].Exporter = func(v any, i int) any { switch v := v.(*IDkgSignedDealingTuple); i { case 0: return &v.state @@ -3654,7 +3653,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[20].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[20].Exporter = func(v any, i int) any { switch v := v.(*InitialIDkgDealings); i { case 0: return &v.state @@ -3666,7 +3665,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[21].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[21].Exporter = func(v any, i int) any { switch v := v.(*IDkgComplaint); i { case 0: return &v.state @@ -3678,7 +3677,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[22].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[22].Exporter = func(v any, i int) any { switch v := v.(*IDkgOpening); i { case 0: return &v.state @@ -3690,7 +3689,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[23].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[23].Exporter = func(v any, i int) any { switch v := v.(*ExtendedDerivationPath); i { case 0: return &v.state @@ -3702,7 +3701,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[24].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[24].Exporter = func(v any, i int) any { switch v := v.(*GossipConfig); i { case 0: return &v.state @@ -3714,7 +3713,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[25].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[25].Exporter = func(v any, i int) any { switch v := v.(*SubnetFeatures); i { case 0: return &v.state @@ -3726,7 +3725,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[26].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[26].Exporter = func(v any, i int) any { switch v := v.(*EcdsaConfig); i { case 0: return &v.state @@ -3738,7 +3737,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[27].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[27].Exporter = func(v any, i int) any { switch v := v.(*SchnorrKeyId); i { case 0: return &v.state @@ -3750,7 +3749,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[28].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[28].Exporter = func(v any, i int) any { switch v := v.(*MasterPublicKeyId); i { case 0: return &v.state @@ -3762,7 +3761,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[29].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[29].Exporter = func(v any, i int) any { switch v := v.(*KeyConfig); i { case 0: return &v.state @@ -3774,7 +3773,7 @@ func file_subnet_proto_init() { return nil } } - file_subnet_proto_msgTypes[30].Exporter = func(v interface{}, i int) interface{} { + file_subnet_proto_msgTypes[30].Exporter = func(v any, i int) any { switch v := v.(*ChainKeyConfig); i { case 0: return &v.state @@ -3787,15 +3786,15 @@ func file_subnet_proto_init() { } } } - file_subnet_proto_msgTypes[0].OneofWrappers = []interface{}{} - file_subnet_proto_msgTypes[25].OneofWrappers = []interface{}{} - file_subnet_proto_msgTypes[26].OneofWrappers = []interface{}{} - file_subnet_proto_msgTypes[28].OneofWrappers = []interface{}{ + file_subnet_proto_msgTypes[0].OneofWrappers = []any{} + file_subnet_proto_msgTypes[25].OneofWrappers = []any{} + file_subnet_proto_msgTypes[26].OneofWrappers = []any{} + file_subnet_proto_msgTypes[28].OneofWrappers = []any{ (*MasterPublicKeyId_Ecdsa)(nil), (*MasterPublicKeyId_Schnorr)(nil), } - file_subnet_proto_msgTypes[29].OneofWrappers = []interface{}{} - file_subnet_proto_msgTypes[30].OneofWrappers = []interface{}{} + file_subnet_proto_msgTypes[29].OneofWrappers = []any{} + file_subnet_proto_msgTypes[30].OneofWrappers = []any{} type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ diff --git a/registry/proto/v1/transport.pb.go b/clients/registry/proto/v1/transport.pb.go similarity index 97% rename from registry/proto/v1/transport.pb.go rename to clients/registry/proto/v1/transport.pb.go index 26c43d9..0a966bf 100644 --- a/registry/proto/v1/transport.pb.go +++ b/clients/registry/proto/v1/transport.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.34.1 -// protoc v5.26.1 +// protoc-gen-go v1.34.2 +// protoc v5.27.0 // source: transport.proto // Set of messages used to interact with the registry canister. @@ -117,7 +117,7 @@ var file_transport_proto_depIdxs = []int32{ var file_transport_proto_enumTypes = make([]protoimpl.EnumInfo, 2) -var file_transport_proto_goTypes = []interface{}{ +var file_transport_proto_goTypes = []any{ (RegistryError_Code)(0), // 0: ic_registry_transport.pb.v1.RegistryError.Code (RegistryMutation_Type)(0), // 1: ic_registry_transport.pb.v1.RegistryMutation.Type (*RegistryError)(nil), // 2: ic_registry_transport.pb.v1.RegistryError @@ -305,7 +305,7 @@ func file_transport_proto_init() { return } if !protoimpl.UnsafeEnabled { - file_transport_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_transport_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*RegistryError); i { case 0: return &v.state @@ -317,7 +317,7 @@ func file_transport_proto_init() { return nil } } - file_transport_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_transport_proto_msgTypes[1].Exporter = func(v any, i int) any { switch v := v.(*RegistryValue); i { case 0: return &v.state @@ -329,7 +329,7 @@ func file_transport_proto_init() { return nil } } - file_transport_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + file_transport_proto_msgTypes[2].Exporter = func(v any, i int) any { switch v := v.(*RegistryDelta); i { case 0: return &v.state @@ -341,7 +341,7 @@ func file_transport_proto_init() { return nil } } - file_transport_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + file_transport_proto_msgTypes[3].Exporter = func(v any, i int) any { switch v := v.(*RegistryGetChangesSinceRequest); i { case 0: return &v.state @@ -353,7 +353,7 @@ func file_transport_proto_init() { return nil } } - file_transport_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + file_transport_proto_msgTypes[4].Exporter = func(v any, i int) any { switch v := v.(*RegistryGetChangesSinceResponse); i { case 0: return &v.state @@ -365,7 +365,7 @@ func file_transport_proto_init() { return nil } } - file_transport_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + file_transport_proto_msgTypes[5].Exporter = func(v any, i int) any { switch v := v.(*RegistryGetValueRequest); i { case 0: return &v.state @@ -377,7 +377,7 @@ func file_transport_proto_init() { return nil } } - file_transport_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + file_transport_proto_msgTypes[6].Exporter = func(v any, i int) any { switch v := v.(*RegistryGetValueResponse); i { case 0: return &v.state @@ -389,7 +389,7 @@ func file_transport_proto_init() { return nil } } - file_transport_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + file_transport_proto_msgTypes[7].Exporter = func(v any, i int) any { switch v := v.(*RegistryGetLatestVersionResponse); i { case 0: return &v.state @@ -401,7 +401,7 @@ func file_transport_proto_init() { return nil } } - file_transport_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + file_transport_proto_msgTypes[8].Exporter = func(v any, i int) any { switch v := v.(*RegistryMutation); i { case 0: return &v.state @@ -413,7 +413,7 @@ func file_transport_proto_init() { return nil } } - file_transport_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + file_transport_proto_msgTypes[9].Exporter = func(v any, i int) any { switch v := v.(*Precondition); i { case 0: return &v.state @@ -425,7 +425,7 @@ func file_transport_proto_init() { return nil } } - file_transport_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + file_transport_proto_msgTypes[10].Exporter = func(v any, i int) any { switch v := v.(*RegistryAtomicMutateRequest); i { case 0: return &v.state @@ -437,7 +437,7 @@ func file_transport_proto_init() { return nil } } - file_transport_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + file_transport_proto_msgTypes[11].Exporter = func(v any, i int) any { switch v := v.(*RegistryAtomicMutateResponse); i { case 0: return &v.state @@ -449,7 +449,7 @@ func file_transport_proto_init() { return nil } } - file_transport_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { + file_transport_proto_msgTypes[12].Exporter = func(v any, i int) any { switch v := v.(*MixedHashTree); i { case 0: return &v.state @@ -461,7 +461,7 @@ func file_transport_proto_init() { return nil } } - file_transport_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { + file_transport_proto_msgTypes[13].Exporter = func(v any, i int) any { switch v := v.(*CertifiedResponse); i { case 0: return &v.state @@ -473,7 +473,7 @@ func file_transport_proto_init() { return nil } } - file_transport_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} { + file_transport_proto_msgTypes[14].Exporter = func(v any, i int) any { switch v := v.(*MixedHashTree_Fork); i { case 0: return &v.state @@ -485,7 +485,7 @@ func file_transport_proto_init() { return nil } } - file_transport_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} { + file_transport_proto_msgTypes[15].Exporter = func(v any, i int) any { switch v := v.(*MixedHashTree_Labeled); i { case 0: return &v.state @@ -498,7 +498,7 @@ func file_transport_proto_init() { } } } - file_transport_proto_msgTypes[12].OneofWrappers = []interface{}{ + file_transport_proto_msgTypes[12].OneofWrappers = []any{ (*MixedHashTree_Empty)(nil), (*MixedHashTree_Fork_)(nil), (*MixedHashTree_Labeled_)(nil), @@ -1670,7 +1670,6 @@ func (x *RegistryValue) Reset() { func (x *RegistryValue) String() string { return protoimpl.X.MessageStringOf(x) } - type isMixedHashTree_TreeEnum interface { isMixedHashTree_TreeEnum() } diff --git a/registry/testdata/local.proto b/clients/registry/testdata/local.proto similarity index 100% rename from registry/testdata/local.proto rename to clients/registry/testdata/local.proto diff --git a/registry/testdata/node.proto b/clients/registry/testdata/node.proto similarity index 100% rename from registry/testdata/node.proto rename to clients/registry/testdata/node.proto diff --git a/registry/testdata/operator.proto b/clients/registry/testdata/operator.proto similarity index 100% rename from registry/testdata/operator.proto rename to clients/registry/testdata/operator.proto diff --git a/registry/testdata/registry.proto b/clients/registry/testdata/registry.proto similarity index 100% rename from registry/testdata/registry.proto rename to clients/registry/testdata/registry.proto diff --git a/registry/testdata/subnet.proto b/clients/registry/testdata/subnet.proto similarity index 100% rename from registry/testdata/subnet.proto rename to clients/registry/testdata/subnet.proto diff --git a/registry/testdata/transport.proto b/clients/registry/testdata/transport.proto similarity index 100% rename from registry/testdata/transport.proto rename to clients/registry/testdata/transport.proto diff --git a/gen/templates/agent_indirect.gotmpl b/gen/templates/agent_indirect.gotmpl index 5f5a9a2..cc4c63d 100644 --- a/gen/templates/agent_indirect.gotmpl +++ b/gen/templates/agent_indirect.gotmpl @@ -49,8 +49,9 @@ func (a {{ $.AgentName }}Agent) {{ .Name }}({{ range $i, $e := .ArgumentTypes }} } // {{ .Name }}{{ .Type }} creates an indirect representation of the "{{ .RawName }}" method on the "{{ $.CanisterName }}" canister. -func (a {{ $.AgentName }}Agent) {{ .Name }}{{ .Type }}({{ range $i, $e := .ArgumentTypes }}{{ if $i }}, {{ end }}{{ $e.Name }} {{ $e.Type }}{{ end }}) (*agent.{{ .Type }},error) { - return a.Agent.Create{{ .Type }}( +func (a {{ $.AgentName }}Agent) {{ .Name }}{{ .Type }}({{ range $i, $e := .ArgumentTypes }}{{ if $i }}, {{ end }}{{ $e.Name }} {{ $e.Type }}{{ end }}) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestType{{ .Type }}, a.CanisterId, "{{ .RawName }}",{{ range $i, $e := .ArgumentTypes }} {{ $e.Name }},{{ end }} diff --git a/ic/ic/agent.go b/ic/ic/agent.go index 563ed56..3ef4537 100755 --- a/ic/ic/agent.go +++ b/ic/ic/agent.go @@ -41,8 +41,9 @@ func (a Agent) BitcoinGetBalance(arg0 BitcoinGetBalanceArgs) (*BitcoinGetBalance } // BitcoinGetBalanceCall creates an indirect representation of the "bitcoin_get_balance" method on the "ic" canister. -func (a Agent) BitcoinGetBalanceCall(arg0 BitcoinGetBalanceArgs) (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) BitcoinGetBalanceCall(arg0 BitcoinGetBalanceArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "bitcoin_get_balance", arg0, @@ -64,8 +65,9 @@ func (a Agent) BitcoinGetBalanceQuery(arg0 BitcoinGetBalanceQueryArgs) (*Bitcoin } // BitcoinGetBalanceQueryQuery creates an indirect representation of the "bitcoin_get_balance_query" method on the "ic" canister. -func (a Agent) BitcoinGetBalanceQueryQuery(arg0 BitcoinGetBalanceQueryArgs) (*agent.Query, error) { - return a.Agent.CreateQuery( +func (a Agent) BitcoinGetBalanceQueryQuery(arg0 BitcoinGetBalanceQueryArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeQuery, a.CanisterId, "bitcoin_get_balance_query", arg0, @@ -87,8 +89,9 @@ func (a Agent) BitcoinGetCurrentFeePercentiles(arg0 BitcoinGetCurrentFeePercenti } // BitcoinGetCurrentFeePercentilesCall creates an indirect representation of the "bitcoin_get_current_fee_percentiles" method on the "ic" canister. -func (a Agent) BitcoinGetCurrentFeePercentilesCall(arg0 BitcoinGetCurrentFeePercentilesArgs) (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) BitcoinGetCurrentFeePercentilesCall(arg0 BitcoinGetCurrentFeePercentilesArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "bitcoin_get_current_fee_percentiles", arg0, @@ -110,8 +113,9 @@ func (a Agent) BitcoinGetUtxos(arg0 BitcoinGetUtxosArgs) (*BitcoinGetUtxosResult } // BitcoinGetUtxosCall creates an indirect representation of the "bitcoin_get_utxos" method on the "ic" canister. -func (a Agent) BitcoinGetUtxosCall(arg0 BitcoinGetUtxosArgs) (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) BitcoinGetUtxosCall(arg0 BitcoinGetUtxosArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "bitcoin_get_utxos", arg0, @@ -133,8 +137,9 @@ func (a Agent) BitcoinGetUtxosQuery(arg0 BitcoinGetUtxosQueryArgs) (*BitcoinGetU } // BitcoinGetUtxosQueryQuery creates an indirect representation of the "bitcoin_get_utxos_query" method on the "ic" canister. -func (a Agent) BitcoinGetUtxosQueryQuery(arg0 BitcoinGetUtxosQueryArgs) (*agent.Query, error) { - return a.Agent.CreateQuery( +func (a Agent) BitcoinGetUtxosQueryQuery(arg0 BitcoinGetUtxosQueryArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeQuery, a.CanisterId, "bitcoin_get_utxos_query", arg0, @@ -155,8 +160,9 @@ func (a Agent) BitcoinSendTransaction(arg0 BitcoinSendTransactionArgs) error { } // BitcoinSendTransactionCall creates an indirect representation of the "bitcoin_send_transaction" method on the "ic" canister. -func (a Agent) BitcoinSendTransactionCall(arg0 BitcoinSendTransactionArgs) (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) BitcoinSendTransactionCall(arg0 BitcoinSendTransactionArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "bitcoin_send_transaction", arg0, @@ -178,8 +184,9 @@ func (a Agent) CanisterInfo(arg0 CanisterInfoArgs) (*CanisterInfoResult, error) } // CanisterInfoCall creates an indirect representation of the "canister_info" method on the "ic" canister. -func (a Agent) CanisterInfoCall(arg0 CanisterInfoArgs) (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) CanisterInfoCall(arg0 CanisterInfoArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "canister_info", arg0, @@ -201,8 +208,9 @@ func (a Agent) CanisterStatus(arg0 CanisterStatusArgs) (*CanisterStatusResult, e } // CanisterStatusCall creates an indirect representation of the "canister_status" method on the "ic" canister. -func (a Agent) CanisterStatusCall(arg0 CanisterStatusArgs) (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) CanisterStatusCall(arg0 CanisterStatusArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "canister_status", arg0, @@ -223,8 +231,9 @@ func (a Agent) ClearChunkStore(arg0 ClearChunkStoreArgs) error { } // ClearChunkStoreCall creates an indirect representation of the "clear_chunk_store" method on the "ic" canister. -func (a Agent) ClearChunkStoreCall(arg0 ClearChunkStoreArgs) (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) ClearChunkStoreCall(arg0 ClearChunkStoreArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "clear_chunk_store", arg0, @@ -246,8 +255,9 @@ func (a Agent) CreateCanister(arg0 CreateCanisterArgs) (*CreateCanisterResult, e } // CreateCanisterCall creates an indirect representation of the "create_canister" method on the "ic" canister. -func (a Agent) CreateCanisterCall(arg0 CreateCanisterArgs) (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) CreateCanisterCall(arg0 CreateCanisterArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "create_canister", arg0, @@ -268,8 +278,9 @@ func (a Agent) DeleteCanister(arg0 DeleteCanisterArgs) error { } // DeleteCanisterCall creates an indirect representation of the "delete_canister" method on the "ic" canister. -func (a Agent) DeleteCanisterCall(arg0 DeleteCanisterArgs) (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) DeleteCanisterCall(arg0 DeleteCanisterArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "delete_canister", arg0, @@ -290,8 +301,9 @@ func (a Agent) DepositCycles(arg0 DepositCyclesArgs) error { } // DepositCyclesCall creates an indirect representation of the "deposit_cycles" method on the "ic" canister. -func (a Agent) DepositCyclesCall(arg0 DepositCyclesArgs) (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) DepositCyclesCall(arg0 DepositCyclesArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "deposit_cycles", arg0, @@ -313,8 +325,9 @@ func (a Agent) EcdsaPublicKey(arg0 EcdsaPublicKeyArgs) (*EcdsaPublicKeyResult, e } // EcdsaPublicKeyCall creates an indirect representation of the "ecdsa_public_key" method on the "ic" canister. -func (a Agent) EcdsaPublicKeyCall(arg0 EcdsaPublicKeyArgs) (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) EcdsaPublicKeyCall(arg0 EcdsaPublicKeyArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "ecdsa_public_key", arg0, @@ -336,8 +349,9 @@ func (a Agent) FetchCanisterLogs(arg0 FetchCanisterLogsArgs) (*FetchCanisterLogs } // FetchCanisterLogsQuery creates an indirect representation of the "fetch_canister_logs" method on the "ic" canister. -func (a Agent) FetchCanisterLogsQuery(arg0 FetchCanisterLogsArgs) (*agent.Query, error) { - return a.Agent.CreateQuery( +func (a Agent) FetchCanisterLogsQuery(arg0 FetchCanisterLogsArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeQuery, a.CanisterId, "fetch_canister_logs", arg0, @@ -359,8 +373,9 @@ func (a Agent) HttpRequest(arg0 HttpRequestArgs) (*HttpRequestResult, error) { } // HttpRequestCall creates an indirect representation of the "http_request" method on the "ic" canister. -func (a Agent) HttpRequestCall(arg0 HttpRequestArgs) (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) HttpRequestCall(arg0 HttpRequestArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "http_request", arg0, @@ -381,8 +396,9 @@ func (a Agent) InstallChunkedCode(arg0 InstallChunkedCodeArgs) error { } // InstallChunkedCodeCall creates an indirect representation of the "install_chunked_code" method on the "ic" canister. -func (a Agent) InstallChunkedCodeCall(arg0 InstallChunkedCodeArgs) (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) InstallChunkedCodeCall(arg0 InstallChunkedCodeArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "install_chunked_code", arg0, @@ -403,8 +419,9 @@ func (a Agent) InstallCode(arg0 InstallCodeArgs) error { } // InstallCodeCall creates an indirect representation of the "install_code" method on the "ic" canister. -func (a Agent) InstallCodeCall(arg0 InstallCodeArgs) (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) InstallCodeCall(arg0 InstallCodeArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "install_code", arg0, @@ -426,8 +443,9 @@ func (a Agent) NodeMetricsHistory(arg0 NodeMetricsHistoryArgs) (*NodeMetricsHist } // NodeMetricsHistoryCall creates an indirect representation of the "node_metrics_history" method on the "ic" canister. -func (a Agent) NodeMetricsHistoryCall(arg0 NodeMetricsHistoryArgs) (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) NodeMetricsHistoryCall(arg0 NodeMetricsHistoryArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "node_metrics_history", arg0, @@ -449,8 +467,9 @@ func (a Agent) ProvisionalCreateCanisterWithCycles(arg0 ProvisionalCreateCaniste } // ProvisionalCreateCanisterWithCyclesCall creates an indirect representation of the "provisional_create_canister_with_cycles" method on the "ic" canister. -func (a Agent) ProvisionalCreateCanisterWithCyclesCall(arg0 ProvisionalCreateCanisterWithCyclesArgs) (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) ProvisionalCreateCanisterWithCyclesCall(arg0 ProvisionalCreateCanisterWithCyclesArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "provisional_create_canister_with_cycles", arg0, @@ -471,8 +490,9 @@ func (a Agent) ProvisionalTopUpCanister(arg0 ProvisionalTopUpCanisterArgs) error } // ProvisionalTopUpCanisterCall creates an indirect representation of the "provisional_top_up_canister" method on the "ic" canister. -func (a Agent) ProvisionalTopUpCanisterCall(arg0 ProvisionalTopUpCanisterArgs) (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) ProvisionalTopUpCanisterCall(arg0 ProvisionalTopUpCanisterArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "provisional_top_up_canister", arg0, @@ -494,8 +514,9 @@ func (a Agent) RawRand() (*RawRandResult, error) { } // RawRandCall creates an indirect representation of the "raw_rand" method on the "ic" canister. -func (a Agent) RawRandCall() (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) RawRandCall() (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "raw_rand", ) @@ -516,8 +537,9 @@ func (a Agent) SignWithEcdsa(arg0 SignWithEcdsaArgs) (*SignWithEcdsaResult, erro } // SignWithEcdsaCall creates an indirect representation of the "sign_with_ecdsa" method on the "ic" canister. -func (a Agent) SignWithEcdsaCall(arg0 SignWithEcdsaArgs) (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) SignWithEcdsaCall(arg0 SignWithEcdsaArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "sign_with_ecdsa", arg0, @@ -538,8 +560,9 @@ func (a Agent) StartCanister(arg0 StartCanisterArgs) error { } // StartCanisterCall creates an indirect representation of the "start_canister" method on the "ic" canister. -func (a Agent) StartCanisterCall(arg0 StartCanisterArgs) (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) StartCanisterCall(arg0 StartCanisterArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "start_canister", arg0, @@ -560,8 +583,9 @@ func (a Agent) StopCanister(arg0 StopCanisterArgs) error { } // StopCanisterCall creates an indirect representation of the "stop_canister" method on the "ic" canister. -func (a Agent) StopCanisterCall(arg0 StopCanisterArgs) (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) StopCanisterCall(arg0 StopCanisterArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "stop_canister", arg0, @@ -583,8 +607,9 @@ func (a Agent) StoredChunks(arg0 StoredChunksArgs) (*StoredChunksResult, error) } // StoredChunksCall creates an indirect representation of the "stored_chunks" method on the "ic" canister. -func (a Agent) StoredChunksCall(arg0 StoredChunksArgs) (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) StoredChunksCall(arg0 StoredChunksArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "stored_chunks", arg0, @@ -605,8 +630,9 @@ func (a Agent) UninstallCode(arg0 UninstallCodeArgs) error { } // UninstallCodeCall creates an indirect representation of the "uninstall_code" method on the "ic" canister. -func (a Agent) UninstallCodeCall(arg0 UninstallCodeArgs) (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) UninstallCodeCall(arg0 UninstallCodeArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "uninstall_code", arg0, @@ -627,8 +653,9 @@ func (a Agent) UpdateSettings(arg0 UpdateSettingsArgs) error { } // UpdateSettingsCall creates an indirect representation of the "update_settings" method on the "ic" canister. -func (a Agent) UpdateSettingsCall(arg0 UpdateSettingsArgs) (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) UpdateSettingsCall(arg0 UpdateSettingsArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "update_settings", arg0, @@ -650,8 +677,9 @@ func (a Agent) UploadChunk(arg0 UploadChunkArgs) (*UploadChunkResult, error) { } // UploadChunkCall creates an indirect representation of the "upload_chunk" method on the "ic" canister. -func (a Agent) UploadChunkCall(arg0 UploadChunkArgs) (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) UploadChunkCall(arg0 UploadChunkArgs) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "upload_chunk", arg0, @@ -765,6 +793,7 @@ type CanisterSettings struct { FreezingThreshold *idl.Nat `ic:"freezing_threshold,omitempty" json:"freezing_threshold,omitempty"` ReservedCyclesLimit *idl.Nat `ic:"reserved_cycles_limit,omitempty" json:"reserved_cycles_limit,omitempty"` LogVisibility *LogVisibility `ic:"log_visibility,omitempty" json:"log_visibility,omitempty"` + WasmMemoryLimit *idl.Nat `ic:"wasm_memory_limit,omitempty" json:"wasm_memory_limit,omitempty"` } type CanisterStatusArgs struct { @@ -850,6 +879,7 @@ type DefiniteCanisterSettings struct { FreezingThreshold idl.Nat `ic:"freezing_threshold" json:"freezing_threshold"` ReservedCyclesLimit idl.Nat `ic:"reserved_cycles_limit" json:"reserved_cycles_limit"` LogVisibility LogVisibility `ic:"log_visibility" json:"log_visibility"` + WasmMemoryLimit idl.Nat `ic:"wasm_memory_limit" json:"wasm_memory_limit"` } type DeleteCanisterArgs struct { diff --git a/ic/registry/agent.go b/ic/registry/agent.go index 8319f60..7592519 100755 --- a/ic/registry/agent.go +++ b/ic/registry/agent.go @@ -219,19 +219,6 @@ func (a Agent) CreateSubnet(arg0 CreateSubnetPayload) error { return nil } -// DeleteSubnet calls the "delete_subnet" method on the "registry" canister. -func (a Agent) DeleteSubnet(arg0 DeleteSubnetPayload) error { - if err := a.Agent.Call( - a.CanisterId, - "delete_subnet", - []any{arg0}, - []any{}, - ); err != nil { - return err - } - return nil -} - // DeployGuestosToAllSubnetNodes calls the "deploy_guestos_to_all_subnet_nodes" method on the "registry" canister. func (a Agent) DeployGuestosToAllSubnetNodes(arg0 DeployGuestosToAllSubnetNodesPayload) error { if err := a.Agent.Call( diff --git a/ic/sns/ledger/agent.go b/ic/sns/ledger/agent.go index 9f0704a..544880a 100755 --- a/ic/sns/ledger/agent.go +++ b/ic/sns/ledger/agent.go @@ -87,6 +87,26 @@ func (a Agent) GetTransactions(arg0 GetTransactionsRequest) (*GetTransactionsRes return &r0, nil } +// Icrc10SupportedStandards calls the "icrc10_supported_standards" method on the "ledger" canister. +func (a Agent) Icrc10SupportedStandards() (*[]struct { + Name string `ic:"name" json:"name"` + Url string `ic:"url" json:"url"` +}, error) { + var r0 []struct { + Name string `ic:"name" json:"name"` + Url string `ic:"url" json:"url"` + } + if err := a.Agent.Query( + a.CanisterId, + "icrc10_supported_standards", + []any{}, + []any{&r0}, + ); err != nil { + return nil, err + } + return &r0, nil +} + // Icrc1BalanceOf calls the "icrc1_balance_of" method on the "ledger" canister. func (a Agent) Icrc1BalanceOf(arg0 Account) (*Tokens, error) { var r0 Tokens @@ -233,6 +253,20 @@ func (a Agent) Icrc1Transfer(arg0 TransferArg) (*TransferResult, error) { return &r0, nil } +// Icrc21CanisterCallConsentMessage calls the "icrc21_canister_call_consent_message" method on the "ledger" canister. +func (a Agent) Icrc21CanisterCallConsentMessage(arg0 Icrc21ConsentMessageRequest) (*Icrc21ConsentMessageResponse, error) { + var r0 Icrc21ConsentMessageResponse + if err := a.Agent.Call( + a.CanisterId, + "icrc21_canister_call_consent_message", + []any{arg0}, + []any{&r0}, + ); err != nil { + return nil, err + } + return &r0, nil +} + // Icrc2Allowance calls the "icrc2_allowance" method on the "ledger" canister. func (a Agent) Icrc2Allowance(arg0 AllowanceArgs) (*Allowance, error) { var r0 Allowance @@ -485,7 +519,7 @@ type GetBlocksResult struct { } `ic:"blocks" json:"blocks"` ArchivedBlocks []struct { Args []GetBlocksArgs `ic:"args" json:"args"` - Callback struct { /* NOT SUPPORTED */ + Callback struct { /* NOT SUPPORTED */ } `ic:"callback" json:"callback"` } `ic:"archived_blocks" json:"archived_blocks"` } @@ -542,6 +576,60 @@ type ICRC3Value struct { } `ic:"Map,variant"` } +type Icrc21ConsentInfo struct { + ConsentMessage Icrc21ConsentMessage `ic:"consent_message" json:"consent_message"` + Metadata Icrc21ConsentMessageMetadata `ic:"metadata" json:"metadata"` +} + +type Icrc21ConsentMessage struct { + GenericDisplayMessage *string `ic:"GenericDisplayMessage,variant"` + LineDisplayMessage *struct { + Pages []struct { + Lines []string `ic:"lines" json:"lines"` + } `ic:"pages" json:"pages"` + } `ic:"LineDisplayMessage,variant"` +} + +type Icrc21ConsentMessageMetadata struct { + Language string `ic:"language" json:"language"` +} + +type Icrc21ConsentMessageRequest struct { + Method string `ic:"method" json:"method"` + Arg []byte `ic:"arg" json:"arg"` + UserPreferences Icrc21ConsentMessageSpec `ic:"user_preferences" json:"user_preferences"` +} + +type Icrc21ConsentMessageResponse struct { + Ok *Icrc21ConsentInfo `ic:"Ok,variant"` + Err *Icrc21Error `ic:"Err,variant"` +} + +type Icrc21ConsentMessageSpec struct { + Metadata Icrc21ConsentMessageMetadata `ic:"metadata" json:"metadata"` + DeviceSpec *struct { + GenericDisplay *idl.Null `ic:"GenericDisplay,variant"` + LineDisplay *struct { + CharactersPerLine uint16 `ic:"characters_per_line" json:"characters_per_line"` + LinesPerPage uint16 `ic:"lines_per_page" json:"lines_per_page"` + } `ic:"LineDisplay,variant"` + } `ic:"device_spec,omitempty" json:"device_spec,omitempty"` +} + +type Icrc21Error struct { + UnsupportedCanisterCall *Icrc21ErrorInfo `ic:"UnsupportedCanisterCall,variant"` + ConsentMessageUnavailable *Icrc21ErrorInfo `ic:"ConsentMessageUnavailable,variant"` + InsufficientPayment *Icrc21ErrorInfo `ic:"InsufficientPayment,variant"` + GenericError *struct { + ErrorCode idl.Nat `ic:"error_code" json:"error_code"` + Description string `ic:"description" json:"description"` + } `ic:"GenericError,variant"` +} + +type Icrc21ErrorInfo struct { + Description string `ic:"description" json:"description"` +} + type InitArgs struct { MintingAccount Account `ic:"minting_account" json:"minting_account"` FeeCollectorAccount *Account `ic:"fee_collector_account,omitempty" json:"fee_collector_account,omitempty"` diff --git a/ic/sns/swap/agent.go b/ic/sns/swap/agent.go index 1501fad..17708d5 100755 --- a/ic/sns/swap/agent.go +++ b/ic/sns/swap/agent.go @@ -305,21 +305,6 @@ func (a Agent) RefreshBuyerTokens(arg0 RefreshBuyerTokensRequest) (*RefreshBuyer return &r0, nil } -// RestoreDappControllers calls the "restore_dapp_controllers" method on the "swap" canister. -func (a Agent) RestoreDappControllers(arg0 struct { -}) (*SetDappControllersCallResult, error) { - var r0 SetDappControllersCallResult - if err := a.Agent.Call( - a.CanisterId, - "restore_dapp_controllers", - []any{arg0}, - []any{&r0}, - ); err != nil { - return nil, err - } - return &r0, nil -} - type BuyerState struct { Icp *TransferableAmount `ic:"icp,omitempty" json:"icp,omitempty"` HasCreatedNeuronRecipes *bool `ic:"has_created_neuron_recipes,omitempty" json:"has_created_neuron_recipes,omitempty"` diff --git a/ic/sns/testdata/gen.go b/ic/sns/testdata/gen.go index 42230b1..df863a0 100644 --- a/ic/sns/testdata/gen.go +++ b/ic/sns/testdata/gen.go @@ -16,6 +16,9 @@ import ( var ( //go:embed did dids embed.FS + + ICVersion = "release-2024-06-05_23-01-base" + SDKVersion = "0.20.1" ) func checkLatest() error { @@ -25,27 +28,27 @@ func checkLatest() error { }{ { filepath: "ic/sns/testdata/did/sns.did", - remote: "https://raw.githubusercontent.com/dfinity/ic/master/rs/nns/sns-wasm/canister/sns-wasm.did", + remote: fmt.Sprintf("https://raw.githubusercontent.com/dfinity/ic/%s/rs/nns/sns-wasm/canister/sns-wasm.did", ICVersion), }, { filepath: "ic/sns/testdata/did/governance.did", - remote: "https://raw.githubusercontent.com/dfinity/sdk/master/src/distributed/assetstorage.did", + remote: fmt.Sprintf("https://raw.githubusercontent.com/dfinity/sdk/%s/src/distributed/assetstorage.did", SDKVersion), }, { filepath: "ic/sns/testdata/did/root.did", - remote: "https://raw.githubusercontent.com/dfinity/ic/master/rs/sns/root/canister/root.did", + remote: fmt.Sprintf("https://raw.githubusercontent.com/dfinity/ic/%s/rs/sns/root/canister/root.did", ICVersion), }, { filepath: "ic/sns/testdata/did/swap.did", - remote: "https://raw.githubusercontent.com/dfinity/ic/master/rs/sns/swap/canister/swap.did", + remote: fmt.Sprintf("https://raw.githubusercontent.com/dfinity/ic/%s/rs/sns/swap/canister/swap.did", ICVersion), }, { filepath: "ic/sns/testdata/did/ledger.did", - remote: "https://raw.githubusercontent.com/dfinity/ic/master/rs/rosetta-api/icrc1/ledger/ledger.did", + remote: fmt.Sprintf("https://raw.githubusercontent.com/dfinity/ic/%s/rs/rosetta-api/icrc1/ledger/ledger.did", ICVersion), }, { filepath: "ic/sns/testdata/did/index.did", - remote: "https://raw.githubusercontent.com/dfinity/ic/master/rs/rosetta-api/icrc1/index/index.did", + remote: fmt.Sprintf("https://raw.githubusercontent.com/dfinity/ic/%s/rs/rosetta-api/icrc1/index/index.did", ICVersion), }, } { raw, err := http.Get(f.remote) diff --git a/ic/testdata/did/ic.did b/ic/testdata/did/ic.did index 3b634a6..6085b24 100644 --- a/ic/testdata/did/ic.did +++ b/ic/testdata/did/ic.did @@ -1,18 +1,12 @@ type canister_id = principal; type wasm_module = blob; -type log_visibility = variant { - controllers; - public; -}; - type canister_settings = record { controllers : opt vec principal; compute_allocation : opt nat; memory_allocation : opt nat; freezing_threshold : opt nat; reserved_cycles_limit : opt nat; - log_visibility : opt log_visibility; }; type definite_canister_settings = record { @@ -21,7 +15,6 @@ type definite_canister_settings = record { memory_allocation : nat; freezing_threshold : nat; reserved_cycles_limit : nat; - log_visibility : log_visibility; }; type change_origin = variant { @@ -55,9 +48,7 @@ type change = record { details : change_details; }; -type chunk_hash = record { - hash : blob; -}; +type chunk_hash = blob; type http_header = record { name : text; @@ -153,7 +144,7 @@ type millisatoshi_per_byte = nat64; type node_metrics = record { node_id : principal; - num_blocks_proposed_total : nat64; + num_blocks_total : nat64; num_block_failures_total : nat64; }; @@ -185,20 +176,14 @@ type stored_chunks_args = record { canister_id : canister_id; }; -type canister_install_mode = variant { - install; - reinstall; - upgrade : opt record { - skip_pre_upgrade : opt bool; - wasm_memory_persistence : opt variant { - keep; - replace; +type install_code_args = record { + mode : variant { + install; + reinstall; + upgrade : opt record { + skip_pre_upgrade : opt bool; }; }; -}; - -type install_code_args = record { - mode : canister_install_mode; canister_id : canister_id; wasm_module : wasm_module; arg : blob; @@ -206,9 +191,15 @@ type install_code_args = record { }; type install_chunked_code_args = record { - mode : canister_install_mode; + mode : variant { + install; + reinstall; + upgrade : opt record { + skip_pre_upgrade : opt bool; + }; + }; target_canister : canister_id; - store_canister : opt canister_id; + storage_canister : opt canister_id; chunk_hashes_list : vec chunk_hash; wasm_module_hash : blob; arg : blob; @@ -240,12 +231,6 @@ type canister_status_result = record { cycles : nat; reserved_cycles : nat; idle_cycles_burned_per_day : nat; - query_stats: record { - num_calls_total: nat; - num_instructions_total: nat; - request_payload_bytes_total: nat; - response_payload_bytes_total: nat; - }; }; type canister_info_args = record { @@ -339,20 +324,6 @@ type bitcoin_get_balance_query_result = satoshi; type bitcoin_get_current_fee_percentiles_result = vec millisatoshi_per_byte; -type fetch_canister_logs_args = record { - canister_id : canister_id; -}; - -type canister_log_record = record { - idx: nat64; - timestamp_nanos: nat64; - content: blob; -}; - -type fetch_canister_logs_result = record { - canister_log_records: vec canister_log_record; -}; - service ic : { create_canister : (create_canister_args) -> (create_canister_result); update_settings : (update_settings_args) -> (); @@ -389,7 +360,4 @@ service ic : { // provisional interfaces for the pre-ledger world provisional_create_canister_with_cycles : (provisional_create_canister_with_cycles_args) -> (provisional_create_canister_with_cycles_result); provisional_top_up_canister : (provisional_top_up_canister_args) -> (); - - // canister logging - fetch_canister_logs : (fetch_canister_logs_args) -> (fetch_canister_logs_result) query; }; diff --git a/ic/testdata/gen.go b/ic/testdata/gen.go index fa91f3b..19b6aee 100644 --- a/ic/testdata/gen.go +++ b/ic/testdata/gen.go @@ -16,6 +16,10 @@ import ( var ( //go:embed did dids embed.FS + + ICVersion = "release-2024-06-05_23-01-base" + InterfaceSpecVersion = "0.23.0" + SDKVersion = "0.20.1" ) func checkLatest() error { @@ -25,31 +29,31 @@ func checkLatest() error { }{ { filepath: "ic/testdata/did/assetstorage.did", - remote: "https://raw.githubusercontent.com/dfinity/sdk/master/src/distributed/assetstorage.did", + remote: fmt.Sprintf("https://raw.githubusercontent.com/dfinity/sdk/%s/src/distributed/assetstorage.did", SDKVersion), }, { filepath: "ic/testdata/did/cmc.did", - remote: "https://raw.githubusercontent.com/dfinity/ic/master/rs/nns/cmc/cmc.did", + remote: fmt.Sprintf("https://raw.githubusercontent.com/dfinity/ic/%s/rs/nns/cmc/cmc.did", ICVersion), }, { filepath: "ic/testdata/did/ic.did", - remote: "https://raw.githubusercontent.com/dfinity/interface-spec/master/spec/_attachments/ic.did", + remote: fmt.Sprintf("https://raw.githubusercontent.com/dfinity/interface-spec/%s/spec/_attachments/ic.did", InterfaceSpecVersion), }, { filepath: "ic/testdata/did/registry.did", - remote: "https://raw.githubusercontent.com/dfinity/ic/master/rs/registry/canister/canister/registry.did", + remote: fmt.Sprintf("https://raw.githubusercontent.com/dfinity/ic/%s/rs/registry/canister/canister/registry.did", ICVersion), }, { filepath: "ic/testdata/did/governance.did", - remote: "https://raw.githubusercontent.com/dfinity/ic/master/rs/nns/governance/canister/governance.did", + remote: fmt.Sprintf("https://raw.githubusercontent.com/dfinity/ic/%s/rs/nns/governance/canister/governance.did", ICVersion), }, { filepath: "ic/testdata/did/icparchive.did", - remote: "https://raw.githubusercontent.com/dfinity/ic/master/rs/rosetta-api/icp_ledger/ledger_archive.did", + remote: fmt.Sprintf("https://raw.githubusercontent.com/dfinity/ic/%s/rs/rosetta-api/icp_ledger/ledger_archive.did", ICVersion), }, { filepath: "ic/testdata/did/icpledger.did", - remote: "https://raw.githubusercontent.com/dfinity/ic/master/rs/rosetta-api/icp_ledger/ledger.did", + remote: fmt.Sprintf("https://raw.githubusercontent.com/dfinity/ic/%s/rs/rosetta-api/icp_ledger/ledger.did", ICVersion), }, { filepath: "ic/testdata/did/icrc1.did", @@ -57,7 +61,7 @@ func checkLatest() error { }, { filepath: "ic/testdata/did/wallet.did", - remote: "https://raw.githubusercontent.com/dfinity/sdk/master/src/distributed/wallet.did", + remote: fmt.Sprintf("https://raw.githubusercontent.com/dfinity/sdk/%s/src/distributed/wallet.did", SDKVersion), }, } { raw, err := http.Get(f.remote) diff --git a/pocketic/agent_test.go b/pocketic/agent_test.go index bfcb1f1..e517e34 100755 --- a/pocketic/agent_test.go +++ b/pocketic/agent_test.go @@ -41,8 +41,9 @@ func (a Agent) HelloQuery(arg0 string) (*string, error) { } // HelloQueryQuery creates an indirect representation of the "helloQuery" method on the "hello" canister. -func (a Agent) HelloQueryQuery(arg0 string) (*agent.Query, error) { - return a.Agent.CreateQuery( +func (a Agent) HelloQueryQuery(arg0 string) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeQuery, a.CanisterId, "helloQuery", arg0, @@ -64,8 +65,9 @@ func (a Agent) HelloUpdate(arg0 string) (*string, error) { } // HelloUpdateCall creates an indirect representation of the "helloUpdate" method on the "hello" canister. -func (a Agent) HelloUpdateCall(arg0 string) (*agent.Call, error) { - return a.Agent.CreateCall( +func (a Agent) HelloUpdateCall(arg0 string) (*agent.CandidAPIRequest, error) { + return a.Agent.CreateCandidAPIRequest( + agent.RequestTypeCall, a.CanisterId, "helloUpdate", arg0, diff --git a/pocketic/endpoints_test.go b/pocketic/endpoints_test.go index 99ff83d..c336301 100644 --- a/pocketic/endpoints_test.go +++ b/pocketic/endpoints_test.go @@ -16,7 +16,7 @@ func TestEndpoints(t *testing.T) { pocketic.WithApplicationSubnet(), ) if err != nil { - t.Fatal(err) + t.Skip(err) } t.Run("status", func(t *testing.T) { diff --git a/pocketic/pocketic_test.go b/pocketic/pocketic_test.go index ddd9000..3bba2b2 100644 --- a/pocketic/pocketic_test.go +++ b/pocketic/pocketic_test.go @@ -21,7 +21,7 @@ import ( func TestConcurrentCalls(t *testing.T) { pic, err := pocketic.New(pocketic.WithPollingDelay(10*time.Millisecond, 10*time.Second)) if err != nil { - t.Fatal(err) + t.Skip(err) } var wg sync.WaitGroup for i := 0; i < 10; i++ { @@ -47,7 +47,7 @@ func TestConcurrentCalls(t *testing.T) { func TestCreateCanister(t *testing.T) { pic, err := pocketic.New(pocketic.WithLogger(new(testLogger))) if err != nil { - t.Fatal(err) + t.Skip(err) } canisterID, err := pic.CreateCanister() @@ -66,7 +66,7 @@ func TestHttpGateway(t *testing.T) { pocketic.WithApplicationSubnet(), ) if err != nil { - t.Fatal(err) + t.Skip(err) } endpoint, err := pic.MakeLive(nil) @@ -101,7 +101,7 @@ func TestHttpGateway(t *testing.T) { if err != nil { t.Fatal(err) } - if err := createCall.WithEffectiveCanisterID(ecID).CallAndWait(&result); err != nil { + if err := createCall.WithEffectiveCanisterID(ecID).CallAndWait([]any{&result}); err != nil { t.Fatal(err) } diff --git a/query.go b/query.go index bdc2deb..fb74e7b 100644 --- a/query.go +++ b/query.go @@ -1,113 +1,25 @@ package agent import ( + "context" "crypto/ed25519" "fmt" - "github.com/aviate-labs/agent-go/candid/idl" + "math/big" + "github.com/aviate-labs/agent-go/certification" "github.com/aviate-labs/agent-go/certification/hashtree" "github.com/aviate-labs/agent-go/principal" "github.com/aviate-labs/leb128" "github.com/fxamacker/cbor/v2" "google.golang.org/protobuf/proto" - "math/big" ) -// CreateQuery creates a new Query to the given canister and method. -func (a *Agent) CreateQuery(canisterID principal.Principal, methodName string, args ...any) (*Query, error) { - rawArgs, err := idl.Marshal(args) - if err != nil { - return nil, err - } - if len(args) == 0 { - // Default to the empty Candid argument list. - rawArgs = []byte{'D', 'I', 'D', 'L', 0, 0} - } - nonce, err := newNonce() - if err != nil { - return nil, err - } - requestID, data, err := a.sign(Request{ - Type: RequestTypeQuery, - Sender: a.Sender(), - CanisterID: canisterID, - MethodName: methodName, - Arguments: rawArgs, - IngressExpiry: a.expiryDate(), - Nonce: nonce, - }) - if err != nil { - return nil, err - } - return &Query{ - a: a, - methodName: methodName, - effectiveCanisterID: effectiveCanisterID(canisterID, args), - requestID: *requestID, - data: data, - }, nil -} - // Query calls a method on a canister and unmarshals the result into the given values. -func (a Agent) Query(canisterID principal.Principal, methodName string, args, values []any) error { - query, err := a.CreateQuery(canisterID, methodName, args...) - if err != nil { - return err - } - return query.Query(values...) -} - -// QueryProto calls a method on a canister and unmarshals the result into the given proto message. -func (a Agent) QueryProto(canisterID principal.Principal, methodName string, in, out proto.Message) error { - payload, err := proto.Marshal(in) - if err != nil { - return err - } - if len(payload) == 0 { - payload = []byte{} - } - _, data, err := a.sign(Request{ - Type: RequestTypeQuery, - Sender: a.Sender(), - IngressExpiry: a.expiryDate(), - CanisterID: canisterID, - MethodName: methodName, - Arguments: payload, - }) - if err != nil { - return err - } - resp, err := a.client.Query(canisterID, data) - if err != nil { - return err - } - var response Response - if err := cbor.Unmarshal(resp, &response); err != nil { - return err - } - if response.Status != "replied" { - return fmt.Errorf("status: %s", response.Status) - } - var reply map[string][]byte - if err := cbor.Unmarshal(response.Reply, &reply); err != nil { - return err - } - return proto.Unmarshal(reply["arg"], out) -} - -// Query is an intermediate representation of a Query to a canister. -type Query struct { - a *Agent - methodName string - effectiveCanisterID principal.Principal - requestID RequestID - data []byte -} - -// Query calls a method on a canister and unmarshals the result into the given values. -func (q Query) Query(values ...any) error { +func (q APIRequest[In, Out]) Query(out Out) error { q.a.logger.Printf("[AGENT] QUERY %s %s", q.effectiveCanisterID, q.methodName) - rawResp, err := q.a.client.Query(q.effectiveCanisterID, q.data) + ctx, cancel := context.WithTimeout(q.a.ctx, q.a.ingressExpiry) + defer cancel() + rawResp, err := q.a.client.Query(ctx, q.effectiveCanisterID, q.data) if err != nil { return err } @@ -196,14 +108,65 @@ func (q Query) Query(values ...any) error { } switch resp.Status { case "replied": - var reply map[string][]byte + var reply struct { + Arg []byte `ic:"arg"` + } if err := cbor.Unmarshal(resp.Reply, &reply); err != nil { return err } - return idl.Unmarshal(reply["arg"], values) + return q.unmarshal(reply.Arg, out) case "rejected": return fmt.Errorf("(%d) %s: %s", resp.RejectCode, resp.ErrorCode, resp.RejectMsg) default: panic("unreachable") } } + +// Query calls a method on a canister and unmarshals the result into the given values. +func (a Agent) Query(canisterID principal.Principal, methodName string, in, out []any) error { + query, err := a.CreateCandidAPIRequest(RequestTypeQuery, canisterID, methodName, in...) + if err != nil { + return err + } + return query.Query(out) +} + +// QueryProto calls a method on a canister and unmarshals the result into the given proto message. +func (a Agent) QueryProto(canisterID principal.Principal, methodName string, in, out proto.Message) error { + payload, err := proto.Marshal(in) + if err != nil { + return err + } + if len(payload) == 0 { + payload = []byte{} + } + _, data, err := a.sign(Request{ + Type: RequestTypeQuery, + Sender: a.Sender(), + IngressExpiry: a.expiryDate(), + CanisterID: canisterID, + MethodName: methodName, + Arguments: payload, + }) + if err != nil { + return err + } + ctx, cancel := context.WithTimeout(a.ctx, a.ingressExpiry) + defer cancel() + resp, err := a.client.Query(ctx, canisterID, data) + if err != nil { + return err + } + var response Response + if err := cbor.Unmarshal(resp, &response); err != nil { + return err + } + if response.Status != "replied" { + return fmt.Errorf("status: %s", response.Status) + } + var reply map[string][]byte + if err := cbor.Unmarshal(response.Reply, &reply); err != nil { + return err + } + return proto.Unmarshal(reply["arg"], out) +}