Code Monkey home page Code Monkey logo

agent-go's People

Contributors

nmattia avatar q-uint avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

agent-go's Issues

Wrong encoding of type variant

Candid definition:

update_secret : (text, nat64, vec SecretConsumer) -> (Result);

Autogenerated types:

type ConsumerPermissionEnum = struct {
	ReadOnly     *struct{} `ic:"ReadOnly,variant"`
	ReadAndWrite *struct{} `ic:"ReadAndWrite,variant"`
}

type SecretConsumer = struct {
	Name           string                 `ic:"name"`
	PermissionType ConsumerPermissionEnum `ic:"permission_type"`
}

Value:

consumers := []SecretConsumer{{Name: id, PermissionType: icp.ConsumerPermissionEnum{ReadAndWrite: &struct{}{}}}}

Expected Behavior

It should work

Actual Behavior

Error on canister decoding arguments:
Canister 47qyl-6qaaa-aaaaa-aabkq-cai trapped explicitly: failed to decode call arguments: Custom(Fail to decode argument 2 from table4 to vec record { name : text; permission_type : variant { ReadOnly; ReadAndWrite } }

Steps to Reproduce the Problem

  1. Create a rust canister that has a method to call a method like this
  2. Generate the candid definition
  3. Create a golang client to run this method
  4. Run that client

Specifications

Version(s):

  • Rust Version(s):

    • candid = "0.10.0"
    • ic-cdk = "0.12.0"
    • ic-cdk-macros = "0.8.2"
  • Golang Version(s):

    • github.com/aviate-labs/agent-go v0.3.1

Segfault occurs when replica cannot be reached

Expected Behavior

If the replica cannot be reached, I would expect a network error or a custom error, not a segfault

Actual Behavior

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x10d105d59]

Steps to Reproduce the Problem

Adapt the README example to use a local replica, and make sure the replica is not running on that port:

package main

import (
	"github.com/aviate-labs/agent-go"
	"github.com/aviate-labs/agent-go/ic"
	"log"
	"net/url"
)

type (
	account struct {
		account string `ic:"account"`
	}

	balance struct {
		e8s uint64 `ic:"e8s"`
	}
)

func main() {
	u, _ := url.parse("http://localhost:4943")
	config := agent.config{
		clientconfig: &agent.clientconfig{host: u},
		fetchrootkey: true,
	}

	a, _ := agent.new(config)

	var balance balance
	if err := a.query(
		ic.ledger_principal, "account_balance_dfx",
		[]any{account{"9523dc824aa062dcd9c91b98f4594ff9c6af661ac96747daef2090b7fe87037d"}},
		[]any{&balance},
	); err != nil {
		log.fatal(err)
	}

	// print(balance.e8s)
	_ = balance // balance{e8s: 0}
}

Specifications

  • Version(s): github.com/aviate-labs/agent-go v0.3.3

Set empty arrays as empty slices

When decoding a response, slices that has no elements inside are not set as empty slices. This issue makes JSON Marshalling process transform them into nil, instead of []. For context, this is actually required in order to generate canonical JSONs equally on Golang, Rust and JS. The default value on other languages is to convert it to [] instead of nil.

References:

Unable to parse Certified Data from canister

On a rust canister, a method is returning the certified data as follows:

let certificate: Option<Vec<u8>> = data_certificate();

The candid interface file is generated automatically from rust code (candid-extractor). From there, the golang client is generated automatically from that file (using goic generator). The golang definition for that file is
Certificate *[]uint8 ic:"certificate,omitempty"

Whenever I try to interact with a canister that has a method like this, I receive this error

cannot unmarshal [217 217 247 162 100 116 114 101 101 131 1 131 1 131 1 131 2 72 99 97 110 105 115 116 101 114 131 1 130 4 88 32 38 80 134 12 2 134 235 186 108 182 171 86 204 145 142 96 24 201 25 0 164 65 67 184 15 198 170 112 211 181 157 121 131 1 130 4 88 32 68 15 133 172 163 218 31 208 115 202 0 228 173 102 84 33 253 55 102 134 207 235 254 133 40 141 174 183 54 142 174 80 131 1 130 4 88 32 1 121 126 235 76 100 24 198 215 119 253 210 2 254 155 166 248 156 227 107 80 143 132 186 213 29 88 146 70 193 69 22 131 1 131 1 130 4 88 32 196 157 56 52 27 67 64 124 118 238 120 45 40 55 83 182 8 154 187 120 173 198 67 32 214 243 202 38 189 125 192 203 131 2 74 0 0 0 0 0 0 0 85 1 1 131 1 131 1 131 1 131 2 78 99 101 114 116 105 102 105 101 100 95 100 97 116 97 130 3 88 32 13 133 172 116 251 23 155 98 81 185 91 61 109 33 148 104 18 228 17 112 168 118 251 79 24 197 178 20 195 42 159 41 130 4 88 32 131 197 107 241 77 222 61 40 222 102 198 146 181 252 157 151 233 221 152 91 106 215 43 15 230 248 78 138 141 243 220 178 130 4 88 32 83 69 49 248 60 7 143 54 16 214 167 154 167 14 136 141 224 181 193 107 102 89 34 233 200 240 220 69 109 147 159 86 130 4 88 32 232 240 48 222 18 185 39 218 146 146 139 158 253 100 216 46 153 62 99 128 225 171 20 110 6 210 200 230 238 210 145 20 130 4 88 32 166 20 17 240 66 194 168 233 68 129 169 222 198 167 61 162 49 153 105 27 183 199 76 46 91 56 253 22 64 255 138 7 130 4 88 32 186 71 224 6 195 219 212 78 87 99 111 252 174 108 73 119 180 163 95 75 195 167 225 37 244 155 116 138 193 178 244 216 130 4 88 32 64 66 97 143 126 48 234 0 238 24 141 89 57 100 20 87 68 7 0 140 136 198 209 204 94 146 90 115 137 195 152 195 131 1 130 4 88 32 201 31 239 34 154 73 123 164 40 211 100 210 38 88 115 122 144 238 214 70 69 113 15 187 113 248 108 66 133 224 201 217 131 2 68 116 105 109 101 130 3 73 136 211 139 241 171 227 247 205 23 105 115 105 103 110 97 116 117 114 101 88 48 163 84 254 25 2 66 192 95 105 130 215 42 248 16 182 39 145 159 165 113 47 230 202 192 185 246 118 155 163 240 114 34 158 26 22 252 195 66 100 241 195 214 248 48 133 147 27 122] into Go value of type *[]uint8

Expected Behavior

Certified Data should be parsed correctly

Actual Behavior

Nasty error indicating the data cannot be parsed.

Steps to Reproduce the Problem

  1. Create a rust canister that has a method to query certified data
  2. Generate the candid definition
  3. Create a golang client to run this method
  4. Run that client

Specifications

  • Rust Version(s):

    • candid = "0.10.0"
    • ic-cdk = "0.12.0"
    • ic-cdk-macros = "0.8.2"
  • Golang Version(s):

    • github.com/aviate-labs/agent-go v0.3.0

JSON tags are missing on generated client with goic CLI

Only ic tags are set with the correct field name. This is a problem whenever JSON marshaling is used, as the correct name for each field is not set. For context, we want to use this to generate canonical json that matches the output obtained on rust canister (and autogenerate JS candid client too)

Expected Behavior

type Consumer = struct {
	Id              string `ic:"id" json:"id"`
	Creator         string `ic:"creator" json:"creator"`
	PendingType     uint8  `ic:"pending_type" json:"pending_type"`
	CreateTimestamp string `ic:"create_timestamp" json:"create_timestamp"`
}

Actual Behavior

type Consumer = struct {
	Id              string `ic:"id"`
	Creator         string `ic:"creator"`
	PendingType     uint8  `ic:"pending_type"`
	CreateTimestamp string `ic:"create_timestamp"`
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.