Git Product home page Git Product logo

eos-go's Introduction

EOS.IO API library for Go

点击查看中文版

GoDoc

This library provides simple access to data structures (binary packing and JSON interface) and API calls to an EOS.IO RPC server, running remotely or locally. It provides wallet functionalities (KeyBag), or can sign transaction through the keosd wallet. It also knows about the P2P protocol on port 9876.

As of before the June launch, this library is pretty much in flux. Don't expect stability, as we're moving alongside the main eosio codebase, which changes very fast.

This library is the basis for the eos-bios launch orchestrator tool at https://github.com/eoscanada/eos-bios

Basic usage

package main

import (
	"context"
	"encoding/json"
	"fmt"

	eos "github.com/eoscanada/eos-go"
	cli "github.com/streamingfast/cli"
)

func main() {
	api := eos.New("https://api.eosn.io")
	ctx := context.Background()

	infoResp, err := api.GetInfo(ctx)
	cli.NoError(err, "unable to get chain info")

	fmt.Println("Chain Info", toJson(infoResp))

	accountResp, _ := api.GetAccount(ctx, "eosio")
	fmt.Println("Account Info", toJson(accountResp))
}

func toJson(v interface{}) string {
	out, err := json.MarshalIndent(v, "", "  ")
	cli.NoError(err, "unable to marshal json")

	return string(out)
}

Examples

Reference

Running

The easiest way to see the actual output for a given example is to add a line // Output: any at the very end of the test, looks like this for ExampleAPI_GetInfo file (examples_api_get_info.go):

	...

    fmt.Println(string(bytes))
    // Output: any
}

This tells go test that it can execute this test correctly. Then, simply run only this example:

go test -run ExampleAPI_GetInfo

Replacing ExampleAPI_GetInfo with the actual example name you want to try out where line // Output: any was added.

This will run the example and compares the standard output with the any which will fail. But it's ok an expected, so you can see the actual output printed to your terminal.

Note Some examples will not succeed out of the box because it requires some configuration. A good example being the transfer operation which requires having the authorizations and balance necessary to perform the transaction. It's quite possible to run them through a development environment however.

Binaries

There is some binaries in main packages under cmd/, mainly around P2P communication.

Environment Variables

All examples uses by default the https://api.eosn.io API endpoint for all HTTP communication and peering.eosn.io for P2P communication. They can respectively be overridden by specifying environment variable EOS_GO_API_URL and EOS_GO_P2P_ENDPOINT respectively.

Tests

Some of our tests renders dates in the timezone of the OS. As such, if you have a bunch of failures around dates and times, it's probably because your timezone is not aligned with those in the tests.

Run the tests with this to be in the same timezone as the expected one in golden files:

TZ=UTC go test ./...

Release

We are using Goreleaser to perform releases. Install the goreleaser binary (instructions) and follow these steps:

  • Dry run release process first with goreleaser release --skip-publish --skip-validate --rm-dist
  • Publish draft release with goreleaser release --rm-dist
  • Open GitHub's release and check that the release is all good
  • Once everything is good, publish release, this will now also push the tag.

Contributing

Any contributions are welcome, use your standard GitHub-fu to pitch in and improve.

License

MIT

eos-go's People

Contributors

abourget avatar akatsuki105 avatar alexcppns avatar alexeyusachev avatar anthonyzzy avatar billettc avatar crazybits avatar dependabot[bot] avatar dix975 avatar emresenyuva avatar errows avatar euforic avatar fanyang1988 avatar fproulx-dfuse avatar fschoell avatar jeiwan avatar jubeless avatar maoueh avatar maxifom avatar noprom avatar openventures avatar patricksalomoneoscanada avatar pnx avatar psy2848048 avatar thbourlove avatar vlastv avatar vovapi avatar xana-rahmani avatar yjwxfq avatar yzprofile 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eos-go's Issues

Support ABI encoder version 1.1

This is a meta issue to track progress of ABI Encoder/Decoder to support ABI version 1.1.

  • ABI Encoder/Decoder (1.1): Supports ABI variants (#59)
  • ABI Encoder/Decoder (1.1): Supports binary extension (#60)

GetActions post omitempty bug

Hi~ EOSCanada's eos-go made development much easier. Thank you.

If the Pos value of GetActionsRequest is set to 0 in the #41 issue added recently, the Pos field will be missing on the actual JSON request by the omitempty option.
This will prevent normal requests from being made.
Should not you change the int64 value of Pos to *int64?

Extracting public key from the signature

func TestSignaturePublicKeyExtraction in ecc/signature_test.go, replaced to FixmeTestSignaturePublicKeyExtraction. Extracting public key from the signature now is not working?

ABI serializer: proof-check float64 serialization

float64 serialization through the ABI encoder outputs a Number, but should output a string in the EOS world.. that's what.

We have a type eos.Float64 to handle that.. we need to make it fit with eos's:

  fc::string to_string(double d)
  {
    // +2 is required to ensure that the double is rounded correctly when read back in.  http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
    std::stringstream ss;
    ss << std::setprecision(std::numeric_limits<double>::digits10 + 2) << std::fixed << d;
    return ss.str();
  }

from fc/src/string.cpp

Get actions API not found.

Hi eoscanada

First, thank you for creating a library.

I have a question, does the library not support the get _ action API?
I'd like to retrieve the transfer details, but I can't find them.
Thank you.

Revise logging strategy

The logging with its reflection currently slows down abi serialization quite drastically.

Let's not expose our logging internals (like Logging). We should have a small hook if someone would like to have our logging piped to some other place.

Thinking of uber's zap

I get block data through the GetBlockByNum No Data

i get block Num 6342084

return :
{"expiration":"2018-07-17T11:19:05","ref_block_num":50301,"ref_block_prefix":2432041012,"max_net_usage_words":0,"max_cpu_usage_ms":0,"delay_sec":0,"context_free_actions":[],"actions":[{"account":"eosdactokens","name":"transfer","authorization":[{"actor":"gy4dkmjzhege","permission":"active"}],"hex_data":"a0986aff49988867100261f9519b8867881300000000000004454f534441430000"}],"transaction_extensions":[],"signatures":["SIG_K1_KXsd17mt6qf8JAHvRiVLRH93tMoQrkC69qhoS2suG8N3YYF54LTVkSwnh4t4wscDJXPnSAdbJZpSfHjJjSurDmwGCAxvTs"],"context_free_data":[]}

sucesss :
image

I can get the complete data through eos-js

here's my code


out,err := eosApi.GetBlockByNum(6342084)
if err != nil {
  log.Println("get block err")
}
signedBlock := out.SignedBlock
	for txNum := range signedBlock.Transactions {
		tx := signedBlock.Transactions[txNum]
		if tx.Transaction.Packed != nil {
			unpacked, err := tx.Transaction.Packed.Unpack()
			if err != nil {
				log.Println(" unpack tractions error  ", err.Error())
			}

			for idx := range unpacked.Actions {
				action := unpacked.Actions[idx]

				if action.Data != nil {
					err := action.MapToRegisteredAction()
					if err != nil {
						log.Fatalf("processAction:ction.MapToRegisteredAction %v", err.Error(),idx)
						continue
					}

					switch op := action.Data.(type) {
					case *token.Transfer:
						log.Printf("Transfer  From : %s , To : %s ",op.From,op.To)	// 191
					}

				}else{
					log.Println("no action.data")
				}
			}
		}
	}

which version(commit) of btcsuite/btced is used

which version(commit) of btcsuite/btced is used, the lastest version of btcsuite/btced do not have the api privKey.SignCanonical, suggest to introduce the vendor management for the third party libs

ABI Encoder/Decoder (1.1): Supports binary extension

Copied from original issue:

Types may have a $ suffix. During binary-to-json conversion, fields with a $ type don't error out when end-of-data has been reached; instead they're omitted. During json-to-binary conversion, missing fields don't error out as long as no non-missing fields follow in the ABI. This omits the bytes from the output stream.

We will need to support this feature in the ABI decoder so previous version if data can continue to be read while newer fields are decoded correctly.

Implementation in: EOSIO/eos#5652
Original issue: EOSIO/eos#5600

EOS Block

Hi

How can I use Original(not nodeos) EOS block Producer Apis to do transactions . Is there any link ?
how can i use eoscanda/Eos-go library to produce original Block on EOS chain .As there is no docs are out from any block producer to use there net to do transaction over EOS chain .

Always get `resource not found` error

I'm playing with the go library, but it always returns resource not found error:

package main

import (
	"fmt"
	"github.com/eoscanada/eos-go"
)

func main() {
	api := eos.New("http://mainnet.eoscalgary.io")
	resp, err := api.GetTransactions(eos.AccountName("gqytiobtgage"))
	if err != nil {
		fmt.Println("Err", err)
	} else {
		fmt.Println(resp)
	}
}

Am I using it the wrong way, or something wrong with the api? thanks!

KeyBag producing invalid signature

I'm trying to create an account using KeyBag as a signer:

	keybag := eos.NewKeyBag()
	err = keybag.Add(a.config.AccountCreator.PrivateKey)
	if err != nil {
		log.Printf("failed to construct signer: %v\n", err)
		internalerror.WriteError(w, internalerror.NewInternalServerError("internal error"))
		return
	}
	api := eos.New(a.config.Network.APIUrl)
	api.Debug = true
	api.SetSigner(keybag)

	out, err := api.SignPushActionsWithOpts([]*eos.Action{
		system.NewNewAccount(eos.AN(a.config.AccountCreator.Username), eos.AN(createAccountRequest.Username), user.GetPublicKey()),
		system.NewBuyRAMBytes(eos.AN(a.config.AccountCreator.Username), eos.AN(createAccountRequest.Username), a.config.AccountCreator.RAM),
		system.NewDelegateBW(
			eos.AN(a.config.AccountCreator.Username),
			eos.AN(createAccountRequest.Username),
			eos.NewEOSAsset(int64(a.config.AccountCreator.CPU*10000)),
			eos.NewEOSAsset(int64(a.config.AccountCreator.Net*10000)),
			false,
		),
	}, &eos.TxOptions{
		ChainID: eos.SHA256Bytes(a.config.Network.ChainID),
	})

However, I'm getting the following error:

-------------------------------
POST /v1/chain/get_required_keys HTTP/1.1
Host: jungle.cryptolions.io:18888

{"available_keys":["EOS87Zpp1FWXkvDAJWMAKcNCc5MUBE45ZxXovzeU8Vhk87B9uayi3"],"transaction":{"expiration":"2018-10-06T22:25:25","ref_block_num":13394,"ref_block_prefix":3292592350,"max_net_usage_words":0,"max_cpu_usage_ms":0,"delay_sec":0,"context_free_actions":[],"actions":[{"account":"eosio","name":"newaccount","authorization":[{"actor":"ababcdcdefef","permission":"active"}],"data":"b0d452092574cc31608c31c618638c3101000000010002cb3f59e17e7b3f2a10c0328862c683b1367ff5f01f6cbe66bbfe8454f259abb00100000001000000010002cb3f59e17e7b3f2a10c0328862c683b1367ff5f01f6cbe66bbfe8454f259abb001000000"},{"account":"eosio","name":"buyrambytes","authorization":[{"actor":"ababcdcdefef","permission":"active"}],"data":"b0d452092574cc31608c31c618638c31800c0000"},{"account":"eosio","name":"delegatebw","authorization":[{"actor":"ababcdcdefef","permission":"active"}],"data":"b0d452092574cc31608c31c618638c31f40100000000000004454f5300000000881300000000000004454f530000000000"}],"transaction_extensions":[]}}

RESPONSE:
{"required_keys":["EOS87Zpp1FWXkvDAJWMAKcNCc5MUBE45ZxXovzeU8Vhk87B9uayi3"]}

-------------------------------
POST /v1/chain/push_transaction HTTP/1.1
Host: jungle.cryptolions.io:18888

{"signatures":["SIG_K1_KhwV2RULiW3pdRW98e1ha12eQ9aSX4YJhC1wSgb2XycogGiN7bzhRe8gEarv7RsXSZxnXNWPCYkBnbTYBpWVxcLpcEJbp4"],"compression":"none","packed_context_free_data":"","packed_trx":"5536b95b5234def840c400000000030000000000ea305500409e9a2264b89a01b0d452092574cc3100000000a8ed323266b0d452092574cc31608c31c618638c3101000000010002cb3f59e17e7b3f2a10c0328862c683b1367ff5f01f6cbe66bbfe8454f259abb00100000001000000010002cb3f59e17e7b3f2a10c0328862c683b1367ff5f01f6cbe66bbfe8454f259abb0010000000000000000ea305500b0cafe4873bd3e01b0d452092574cc3100000000a8ed323214b0d452092574cc31608c31c618638c31800c00000000000000ea305500003f2a1ba6a24a01b0d452092574cc3100000000a8ed323231b0d452092574cc31608c31c618638c31f40100000000000004454f5300000000881300000000000004454f53000000000000"}

2018/10/06 18:24:56 failed to send tx: http://jungle.cryptolions.io:18888/v1/chain/push_transaction: status code=500, body={"code":500,"message":"Internal Service Error","error":{"code":3090003,"name":"unsatisfied_authorization","what":"Provided keys, permissions, and delays do not satisfy declared authorizations","details":[{"message":"transaction declares authority '{\"actor\":\"ababcdcdefef\",\"permission\":\"active\"}', but does not have signatures for it under a provided delay of 0 ms, provided permissions [], provided keys [\"EOS5Dr6KmfMoRjNWuaQgHAY3cQYVr8cFLVqHt1Ynm431332wE6in6\"], and a delay max limit of 3888000000 ms","file":"authorization_manager.cpp","line_number":413,"method":"check_authorization"}]}}

As you can see, I provide KeyBag with the private key for EOS87Zpp1FWXkvDAJWMAKcNCc5MUBE45ZxXovzeU8Vhk87B9uayi3 but the EOS network thinks I'm signing with EOS5Dr6KmfMoRjNWuaQgHAY3cQYVr8cFLVqHt1Ynm431332wE6in6.

Hook in R1 key into `ecc` lib

Starting to see them on mainnet.

We'll also want to update blocksigner with those keys, as it seems the speed of signature is faster than K1 with its funky deterministic nonce loops :)

how to push actions with raw json data?

dear developer, thanks for the great library, i am using it to create dapp.
however when i push action to the chain. the param ActionData: eos.NewActionData(data)})
will be binary string format.

#   13   2018-10-12T02:43:02.000      eosslotloger::result => eosslotloger  94f97639...
"046c6f73741042082184d07befe80300000000000004454f5300000000000000000000000004454f530000000035454f53364d5279416a51713875643768564e5963666e56504a7163567073634e35536f384268744875475971455435474457354356655349475f4b315f4b59364258695a4461446d39514d4b6d5150723278703964737444676d484c6b565469347245b2cd3ea401d963b6fa75dd776a6397b77aef6623f9fabd4aa5c56f695b309af199017b227265656c30223a7b22706f73223a203335202c20226e756d626572223a2036207d2c227265656c31223a7b22706f73223a203134202c20226e756d626572223a2030207d2c227265656c32223a7b22706f73223a2038202c20226e756d626572223a2037207d2c226a61636b706f74223a7b20706f696e743a30202c2022706f73223a2d31202c20226e756d626572223a202d31207d7d4433446b5759547275753144356f795539366e6a727064733147376e3766573348504252454438467336623374323251704d33694d476375403031316361623464373532338079ce0bff770500"

how i can set it to simple JSON format? thanks a lot

How to set owner permission by updateauth ?

How I use NewUpdateAuth:

system.NewUpdateAuth(
		eos.AN("account1"),
		eos.PN("active"),
		eos.PN("owner"),
		eos.Authority...,
		eos.PN("active"),
	)

It's ok when I set active permission. I filled key 'parent' with the value 'owner'.
Then I wanna set owner permission, and I left a blank to key 'parent', but seem no use.
some problems occurs:

1953216ms thread-0 http_plugin.cpp:406 handle_exception ] Exception Details: 3050000 action_validate_exception: action exception
Cannot set an authority as its own parent
{}
thread-0 eosio_contract.cpp:214 apply_eosio_updateauth

So I think the main problem may be the extra key 'parent' shouldn’t be packed when setting
the owner permission. Reference issue

got tx_not_found when i use get_transaction

I have setup a test eos node in server and try the below steps:

1、 push a transaction

       a := &eos.Action{
		Account:       eos.AN("myaccount"),
		Name:          eos.ActN("post"),
		Authorization: []eos.PermissionLevel{mypl},
		ActionData:    eos.NewActionData("abcdef"),
	}
	info, err := api.GetInfo()
	if err != nil {
		return "", err
	}
	tx := eos.NewTransaction([]*eos.Action{a}, &eos.TxOptions{HeadBlockID: info.HeadBlockID})
	out, err := api.SignPushTransaction(tx, info.chainID, eos.CompressionNone)
	if err != nil {
		return "", err
	}

	//fmt.Println("id:", hex.EncodeToString(out.Processed.ID))
	return out.TransactionID, nil

it returns tx is such as "4253e47a27c9e523c5590fbb18651c4d25f49bd2a792d8be9becafdec50b8fa0"

2、 use api.GetBlockByNum to check the transaction

resp, err := s.eosAPI.GetBlockByNum(blockNum)
.......
for _, tr := range resp.Transactions {
		tx, err := tr.Transaction.Packed.Unpack()
		if err == nil {
			fmt.Printf("tx: %+v\n", hex.EncodeToString(tr.Transaction.ID))
		}
	}

I can get the transaction id

3、use GetTransaction

when I use GetTransaction to query this transaction, it returns tx_not_found

GetTransaction("4253e47a27c9e523c5590fbb18651c4d25f49bd2a792d8be9becafdec50b8fa0")
status code=500, body={"code":500,"message":"Internal Service Error","error":{"code":3040011,"name":"tx_not_found","what":"The transaction can not be found","details":[]}

4、if I use cleos to get this transaction, it returns also tx_not_found

I don't know why not query transactions?

Hide debug output from p2p sub-package

fmt.Printf("Out of sync by %d blocks \n", delta)

fmt.Printf("Requestion block from %d to %d\n", syncHeadBlock, requestedBlock)

fmt.Println("In sync ... Sending handshake!!!")

eos-go/p2p/client.go

Lines 212 to 214 in f320fb2

fmt.Println("************************************")
fmt.Printf("Requestion more block from %d to %d\n", syncHeadBlock, requestedBlock)
fmt.Println("************************************")

etc

It's making usage of package frustrating

Signature is different

I generate a simple transaction through the command cleos with -d -j options. Then I used eos.NewSignedTransaction() with the parameters in the json string(generated by cleos) . However the two signatures are different.
Have you tested this?
If I am wrong, would you please give an example?

Why struct TransactionWithID' ID is uint8?

in p2p_types.go, there is a struct of TransactionWithID:
type TransactionWithID struct {
ID uint8 //
Packed PackedTransaction
}
because ID's format like "00160d6f62968d7e04eab28658c854b7f838249499115a6504dcbc1a42da9f3a" is what I got by get_blockinfo api, I am wondering why type of ID is uint8?
can someone explain? thanks.

Error in NewAction

Dawn3.0 localnet
I deployed the contract "eosio.token" on chain and follow the official guide.
All goes well when I use command line tool

cleos push action eosio.token transfer '["usera", "userb", "1 EOS", "memo"]' -p usera

to transfer some EOS token.
Then I tried the code:

func (e *eos.API)TransferToken(from, to, memo string, quantity int64) (string, error){
	a := &eos.Action{
		Account: eos.AccountName("eosio.token"),
		Name: eos.ActionName("transfer"),
		Authorization: []eos.PermissionLevel{
			{eos.AccountName(from), eos.PermissionName("active")},
		},
		Data: eos.NewActionData(NewTransaction{
				From: from,
				To: to,
				Quantity: strconv.FormatInt(quantity, 10) + ` EOS`,
				Memo: memo,
		}),
	}

	e.SetSigner(eos.NewWalletSigner(e, "default"))
	tx, err := e.SignPushActions(a)
	if err != nil {
		return "", err
	}
	return tx.TransactionID, nil
}

but it always returns the following error:

status code=400, body={"code":400,"message":"Bad Request","error":{"code":3030000,"name":"transaction_exception","what":"transaction validation exception","details":[{"message":"condition: assertion failed: read","file":"wasm_interface.cpp","line_number":805,"method":"eosio_assert"},{"message":"","file":"apply_context.cpp","line_number":30,"method":"exec_one"},{"message":"","file":"chain_controller.cpp","line_number":1989,"method":"__apply_transaction"},{"message":"","file":"chain_controller.cpp","line_number":2024,"method":"_apply_transaction"},{"message":"","file":"chain_controller.cpp","line_number":2225,"method":"wrap_transaction_processing"},{"message":"","file":"chain_controller.cpp","line_number":353,"method":"_push_transaction"},{"message":"","file":"chain_controller.cpp","line_number":328,"method":"_push_transaction"}]}}

Did I miss something when I tried to make this transaction?

If transaction is packed with CompressionZlib, how to get right transaction id before push ?

I got txid by packedTx.ID().String() before push action,
but it is always different from the txid from
PushTransaction response (PushTransactionFullResp.transactionId).

same to receipt.Transaction.ID.String()

tid1 := packedTx.ID().String()
tid2 := receipt.Transaction.ID.String()
resp, err := n.c.PushTransaction(packed)
if err != nil {
	log.Error("send transaction fail, error: %s", err.Error())
}
tid3 :=  resp.TransactionID

tid1 == tid2 // true
tid1 == tid3 // false

but only tid3 can be searched on the blockchain explorer
please tell me how to get the tid3 before push tx.
thank you
#74

Rename SHA256Bytes to SHA256Hash

This would be a heavy refactor (still most probably a simple search/replace) for all consumers of the library out there.

Should probably go in a major iteration IMO.

Action unmarshalling

RPC calls like get_block or get_transaction seems to return action data in plain json

However, this data isn't returned on eos.go API.GetTransaction or API.GetBlockByNumOrId calls

This data isn't accessible after unpacking packed transaction either. ActionData is always empty.

So, data that is accessible as plain json on RPC call, isn't accessible when using library

Runtime: out of memory error when unpacking transaction

I'm trying to explore blocks using eos-go with http://mainnet.eoscalgary.io/ as API endpoint

When I try to unpack transaction on block 177 I get panic error:

fatal error: runtime: out of memory

runtime stack:
runtime.throw(0x6b5ec5, 0x16)
        /usr/lib/go-1.9/src/runtime/panic.go:605 +0x95
runtime.sysMap(0xc420200000, 0x113c1b0000, 0x5000e8000, 0x83f958)
        /usr/lib/go-1.9/src/runtime/mem_linux.go:216 +0x1d0
runtime.(*mheap).sysAlloc(0x826840, 0x113c1b0000, 0x7f1e9adf4be8)
        /usr/lib/go-1.9/src/runtime/malloc.go:470 +0xd7
runtime.(*mheap).grow(0x826840, 0x89e0d5, 0x0)
        /usr/lib/go-1.9/src/runtime/mheap.go:887 +0x60
runtime.(*mheap).allocSpanLocked(0x826840, 0x89e0d5, 0x83f968, 0x7f1e9aebf428)
        /usr/lib/go-1.9/src/runtime/mheap.go:800 +0x334
runtime.(*mheap).alloc_m(0x826840, 0x89e0d5, 0x7f1e98ea0100, 0x41681c)
        /usr/lib/go-1.9/src/runtime/mheap.go:666 +0x118
runtime.(*mheap).alloc.func1()
        /usr/lib/go-1.9/src/runtime/mheap.go:733 +0x4d
runtime.systemstack(0x7f1e98ea2db0)
        /usr/lib/go-1.9/src/runtime/asm_amd64.s:360 +0xab
runtime.(*mheap).alloc(0x826840, 0x89e0d5, 0x7f1e98010100, 0x415e84)
        /usr/lib/go-1.9/src/runtime/mheap.go:732 +0xa1
runtime.largeAlloc(0x113c1a90f8, 0x7f1e9ae70001, 0xc4201b2475)
        /usr/lib/go-1.9/src/runtime/malloc.go:827 +0x98
runtime.mallocgc.func1()
        /usr/lib/go-1.9/src/runtime/malloc.go:722 +0x46
runtime.systemstack(0xc420028600)
        /usr/lib/go-1.9/src/runtime/asm_amd64.s:344 +0x79
runtime.mstart()
        /usr/lib/go-1.9/src/runtime/proc.go:1135

Code that reproduces behaviour:

package main

import (
	"github.com/eoscanada/eos-go"
	"log"
)

func main() {
	api := eos.New("http://mainnet.eoscalgary.io")
	block, err := api.GetBlockByNum(177)
	if err != nil {
		log.Fatal(err)
	}
	unpacked, err := block.Transactions[0].Transaction.Packed.Unpack()
	if err != nil {
		log.Fatal(err)
	}
	log.Println(unpacked.Actions)

}

Jungle

Do you have plan to make some script for connection to Jungle testnet? Specialy now at start when we test both networks.

How can I create a new account by api ?

I am trying use the function to create a new account , like this :
NewCustomNewAccount
NewBuyRAM
NewDelegateBW
SignPushActions(newAaccountAction, buyRamAction, delegateAction)
but failed , How can I do it ?

parse block error

parse #7897873 block occur below error


panic: runtime error: slice bounds out of range
github.com/eoscanada/eos-go.(*Decoder).readUvarint(0xc421849ea8, 0x0, 0x4ba2b4, 0x84d900)

Unmarshal: json

Unmarshal: json: cannot unmarshal string into Go struct field TransactionReceipt.trx of type eos.Trx

GetTableRows failed!

I have one table:

root@gytan-VirtualBox:~# cleos get table pegzone pegzone transferinfo
{
  "rows": [{
      "id": 0,
      "from": "user",
      "to": "pegzone",
      "quantity": "1.0000 SYS",
      "memo": "xxxxx"
    },{
      "id": 1,
      "from": "pegzone",
      "to": "user",
      "quantity": "1.0000 SYS",
      "memo": "xxx"
    },{
      "id": 2,
      "from": "user",
      "to": "pegzone",
      "quantity": "1.0000 SYS",
      "memo": "cccc"
    },{
      "id": 3,
      "from": "user",
      "to": "pegzone",
      "quantity": "1.0000 SYS",
      "memo": "AAAA"
    },{
      "id": 4,
      "from": "user",
      "to": "pegzone",
      "quantity": "1.0000 SYS",
      "memo": "AAAA"
    },{
      "id": 5,
      "from": "user",
      "to": "pegzone",
      "quantity": "1.0000 SYS",
      "memo": "AAAA"
    }
  ],
  "more": false
}

I get data by the following way:

//
type eostransfer struct {
	id uint64 `json:"id"`
	from eos.AccountName `json:"from"`
	to eos.AccountName `json:"to"`
	quantity eos.Asset  `json:"quantity"`
	memo string `json:"memo"`
}

//
eos_api := eos.New("http://127.0.0.1:8888")
eos_info, _ := eos_api.GetInfo()  //                                                         **successful**

//
gettable_request := eos.GetTableRowsRequest {
	Code: "pegzone",
	Scope: "pegzone",
	Table: "transferinfo",
	LowerBound: strconv.FormatInt(0, 10),
}

//
gettable_response, eos_err := eos_api.GetTableRows(gettable_request)
if eos_err != nil {
	panic("eos get table failed")
}

//
var transfers []*eostransfer
err_json := gettable_response.BinaryToStructs(&transfers)
if err_json != nil {
	panic("eos get table failed")
}

//
c.logger.Info("query chain table", "total", len(transfers)) //                         **6**


for i, tran := range transfers {
	c.logger.Info("eos transfer", "id", tran.id)
	c.logger.Info("eos transfer", "from", tran.from)
	c.logger.Info("eos transfer", "to", tran.to)
	c.logger.Info("eos transfer", "quantity", tran.quantity.String())
	c.logger.Info("eos transfer", "memo", tran.memo)
}
// **id = 0, from & to & memo is empty**

what's going wrong?

About transaction packed document

I am confused about the transaction packed. So can you supply the detail about packing a transaction?
"eos" did not pack for a transaction. Thanks.

Is there a specified reason to use sha256 in `newRandomPrivateKey`?

eos-go/ecc/privkey.go

Lines 25 to 40 in fbd70cf

func newRandomPrivateKey(randSource io.Reader) (*PrivateKey, error) {
rawPrivKey := make([]byte, 32)
written, err := io.ReadFull(randSource, rawPrivKey)
if err != nil {
return nil, fmt.Errorf("error feeding crypto-rand numbers to seed ephemeral private key: %s", err)
}
if written != 32 {
return nil, fmt.Errorf("couldn't write 32 bytes of randomness to seed ephemeral private key")
}
h := sha256.New()
h.Write(rawPrivKey)
privKey, _ := btcec.PrivKeyFromBytes(btcec.S256(), h.Sum(nil))
return &PrivateKey{Curve: CurveK1, privKey: privKey}, nil
}

Hello, fabulous work, love it. 🚀

Just curious, why not use random bytes directly?

Sign and send action param not hex

action object defined

type BetActionData struct {
	Id   int64  `json:"id"`
	Seed string `json:"seed"`
}

new action

action := eos.Action{
				Account:       eos.AccountName("fairdicetest"),
				Name:          eos.ActionName("reveal"),
				Authorization: []eos.PermissionLevel{permissionLevel},
				ActionData:    eos.NewActionData(actionData),
			}

i search my tx on block explorer, i get my data object:

"data": {
                        "id": 23,
                        "seed": "4065373138613239653261373531373664333438343562356335666364656639"
                    }

the seed param is decode to be byte, how can i keep this string no changed

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.