Coder Social home page Coder Social logo

eteu-technologies / near-api-go Goto Github PK

View Code? Open in Web Editor NEW
16.0 3.0 13.0 253 KB

Go library to interact with NEAR Protocol via RPC API (https://docs.near.org/docs/api/rpc)

License: MIT License

Go 98.50% Dockerfile 0.19% Shell 0.59% Nix 0.73%
golang near-protocol rpc-client blockchain near-api-go go

near-api-go's People

Contributors

hoangphuong24984 avatar mikroskeem avatar mllnd avatar sashaduke avatar sergey-shpilevskiy avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

near-api-go's Issues

Add integration tests

Project includes scripts to start up the NEAR localnet, but there are no tests to utilize it in automated way.

AccessKeyView Unmarshal failed

        c, _ := NewClient("https://rpc.testnet.near.org")
	var resp AccessKeyView
	_, _ = c.doRPC(context.Background(), &resp, "query", block.FinalityFinal(), map[string]interface{}{
		"request_type": "view_access_key",
		"account_id":   "yuhainan.testnet",
		"public_key":   "ed25519:AWRz5BzmJUbjKgr6Ln2VcwkuEh8QipRjxGt9YdjNeJn",
	})
        fmt.Println(resp)

Result:

{{91568545000006 {true {<nil>  []}}} {0 11111111111111111111111111111111}}

when i use postman everything is ok
image

how to fix it?

Add issue template

Something in the lines of:

  1. What did you try to do (with code snippet to reproduce)
  2. What did you expect to see?
  3. What did you see instead?
  4. Relevant NEAR network & transaction/block/receipt hash to look up

chunkView Unmarshal exception

The main network blcok 70249973 already supports secp256k1 algorithm,
but sdk still does not support it, currently chunkView Unmarshal exception。

func WrapRawKey(keyType PublicKeyType, key []byte) (pk PublicKey, err error) {
	switch keyType {
	case KeyTypeED25519:
		if len(key) != ed25519.PublicKeySize {
			return pk, ErrInvalidPublicKey
		}

		pk[0] = RawKeyTypeED25519
		copy(pk[1:], key[0:ed25519.PublicKeySize])
		return
	case KeyTypeSECP256K1:
		// TODO!
		return pk, fmt.Errorf("SECP256K1 is not supported yet")
	}

	return pk, ErrInvalidKeyType
}

How to distinguish error types

The error response of near rpc, error.cause.name can distinguish the error type, but near-api-go does not marsh this information to the error struct, because the error struct does not have a cause field, why not add the cause field to the error struct, like

type Cause struct {
	Info interface{} `json:"info"`
	Name string      `json:"name"`
}

type Error struct {
	Cause   Cause           `json:"cause"`
	Code    int             `json:"code"`
	Message string          `json:"message"`
	Data    json.RawMessage `json:"data"`
}

Implement ReceiptView's Receipt parsing

type ReceiptView struct {
PredecessorID types.AccountID json:"predecessor_id"
ReceiverID types.AccountID json:"receiver_id"
ReceiptID hash.CryptoHash json:"receipt_id"
Receipt json.RawMessage json:"receipt" // TODO: needs a type!
}

Now the type of the Receipt field is RawMessage, I have to parse it by gjson.
Of course the better way is use a Receipt Struct.
In nearcore the receipt is a Enum Type, it seems a bit hard to unmarshal it.

Improve documentation

Project API is not thoroughly documented right now, which is very likely unwelcoming for newcomers.

AddKey and DeleteKey Action unsmarshal failed

{ "AddKey": { "access_key": { "nonce": 0, "permission": "FullAccess" }, "public_key": "ed25519:Gm4dtdpxNhAyZRDNnjFxiU3P7SMhAnPvpK7YVehFdJgh" } }

The prefix of the public_key field is 'ed25519:', the action unmarshal function pass it to base58 decoder, however it can't be recognized.

method_name is null?

bugs?
height:65906486
methodName in functioncall of action is null,but mannet db this record is not null .

action.AccessKeyPermission unmarshal failed

1.What did you try to do (with code snippet to reproduce)

chunkRsp, err := sw.rpc.ChunkDetails(ctx, chunkHash)

2.What did you expect to see?

sync success

3.What did you see instead?

cannot unmarshal string into Go struct field SignedTransactionView.transactions.actions of type action.AccessKeyPermission

4.Relevant NEAR network & transaction/block/receipt hash to look up

chunk hash 6P3ftNBttmek2Z8nJamXqzmLWkN8yMc4hMHNRDDAfubB

Tx Broadcasts Failing since recent key changes

Hi there, since the implementing of secp256k1 keys, our transactions are failing to broadcast although we are only using Ed25519 keys - the following error message is received:

RPC error REQUEST_VALIDATION_ERROR (name=PARSE_ERROR, message=Failed to decode transaction: unknown key type '33')

I don't really have time to look into it right now so thought I'd open an issue :)

Kind regards

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.