Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dix975 committed May 15, 2018
1 parent 1f2f4b2 commit 1fecc00
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 87 deletions.
38 changes: 0 additions & 38 deletions actions_test.go
@@ -1,43 +1,5 @@
package eos

import (
"encoding/hex"
"encoding/json"
"testing"

"fmt"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)


func TestActionUnmarshalBinary(t *testing.T) {
tests := []struct {
in string
jsonTx string
}{
{
"967abe5a000003002a48328c0000000000010000000000ea3055000000572d3ccdcd010000000000ea305500000000a8ed32322f0000000000ea3055000000023baca66200a0724e1809000004454f53000000000e57656c636f6d6520306461303930",
"{\"expiration\":\"2018-03-30T17:57:42\",\"region\":0,\"ref_block_num\":3,\"ref_block_prefix\":2352105514,\"max_net_usage_words\":0,\"max_kcpu_usage\":0,\"delay_sec\":0}",
},
}

for _, test := range tests {
var tx Transaction
b, err := hex.DecodeString(test.in)
require.NoError(t, err)

decoder := NewDecoder(b)
require.NoError(t, decoder.Decode(&tx))

js, err := json.Marshal(tx)
require.NoError(t, err)
assert.Equal(t, test.jsonTx, string(js))
}

}

// FETCHED FROM A SIMILAR TRANSACTION VIA `eosioc`, includes the Transaction headers though:
// This was BEFORE the `keys` and `accounts` were swapped on `Authority`.
// transaction header:
Expand Down
1 change: 1 addition & 0 deletions api.go
Expand Up @@ -291,6 +291,7 @@ func (api *API) GetBlockByID(id string) (out *BlockResp, err error) {

func (api *API) GetBlockByNum(num uint64) (out *BlockResp, err error) {
err = api.call("chain", "get_block", M{"block_num_or_id": fmt.Sprintf("%d", num)}, &out)
//err = api.call("chain", "get_block", M{"block_num_or_id": num}, &out)
return
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/eos-p2p-client/main.go
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/eoscanada/eos-go/p2p"
)

var apiAddr = flag.String("api-addr", "http://stage2.eoscanada.com", "RPC endpoint of the nodeos instance")
var p2pAddr = flag.String("p2p-addr", "stage2.eoscanada.com:9876", "P2P socket connection")
var apiAddr = flag.String("api-addr", "http://patrick.testnets.eoscanada.com", "RPC endpoint of the nodeos instance")
var p2pAddr = flag.String("p2p-addr", "patrick.testnets.eoscanada.com:9876", "P2P socket connection")
var signingKey = flag.String("signing-key", "5J5EE2cBDM4d3vWpKGcJsgiagsLVZkgWjJpxacz9mXodemXex6K", "Key to sign transactions we're about to blast")
var chainID = flag.String("chain-id", "0000000000000000000000000000000000000000000000000000000000000000", "Chain id")
var networkVersion = flag.Int("network-version", 25431, "Chain id")
Expand Down
2 changes: 1 addition & 1 deletion cmd/eos-p2p-proxy/main.go
Expand Up @@ -8,7 +8,7 @@ func main() {

proxy := p2p.Proxy{
Routes: []*p2p.Route{
{From: ":8902", To: "stage2.eoscanada.com:9876"},
{From: ":19876", To: "patrick.testnets.eoscanada.com:9876"},
},
Handlers: []p2p.Handler{
//p2p.StringLoggerHandler,
Expand Down
2 changes: 1 addition & 1 deletion ecc/signature.go
Expand Up @@ -92,7 +92,7 @@ func NewSignature(fromText string) (Signature, error) {

content := sigbytes[:len(sigbytes)-4]
checksum := sigbytes[len(sigbytes)-4:]
verifyChecksum := ripemd160checksum(content, curveID)
verifyChecksum := ripemd160checksumHashCurve(content, curveID)
if !bytes.Equal(verifyChecksum, checksum) {
return Signature{}, fmt.Errorf("signature checksum failed, found %x expected %x", verifyChecksum, checksum)
}
Expand Down
7 changes: 7 additions & 0 deletions ecc/signature_test.go
Expand Up @@ -52,6 +52,13 @@ func TestSignatureMarshalUnmarshal(t *testing.T) {
assert.Equal(t, fromEOSIOC, sig.String())
assert.True(t, isCanonical([]byte(sig.Content)))
}
func TestSignatureMarshalUnmarshal_bilc(t *testing.T) {
fromEOSIOC := "SIG_K1_Jy9G6SgmGSjAbu7n82veUiqV8LFFL6wqr9G26H37dy1WExUj9kYwS17X3ffT5W9M51HkpKF4xQ6MoFCCMxBEHbk64dgbMg"
sig, err := NewSignature(fromEOSIOC)
require.NoError(t, err)
assert.Equal(t, fromEOSIOC, sig.String())
assert.True(t, isCanonical([]byte(sig.Content)))
}

func isCanonical(compactSig []byte) bool {
// !(c.data[1] & 0x80)
Expand Down
1 change: 1 addition & 0 deletions name_test.go
@@ -0,0 +1 @@
package eos
6 changes: 2 additions & 4 deletions p2p.go
Expand Up @@ -23,10 +23,9 @@ const (
NoticeMessageType
RequestMessageType
SyncRequestMessageType
SignedBlockSummaryMessageType
SignedBlockMessageType
SignedTransactionMessageType
PackedTransactionMessageType
ChainSizeType
)

type MessageReflectTypes struct {
Expand All @@ -41,10 +40,9 @@ var messageAttributes = []MessageReflectTypes{
{Name: "Notice", ReflectType: reflect.TypeOf(NoticeMessage{})},
{Name: "Request", ReflectType: reflect.TypeOf(RequestMessage{})},
{Name: "SyncRequest", ReflectType: reflect.TypeOf(SyncRequestMessage{})},
{Name: "SignedBlockSummary", ReflectType: reflect.TypeOf(SignedBlockSummaryMessage{})},
{Name: "SignedBlock", ReflectType: reflect.TypeOf(SignedBlockMessage{})},
{Name: "SignedTransaction", ReflectType: reflect.TypeOf(SignedTransactionMessage{})},
{Name: "PackedTransaction", ReflectType: reflect.TypeOf(PackedTransactionMessage{})},
{Name: "ChainSize", ReflectType: reflect.TypeOf(ChainSizeMessage{})},
}

var ErrUnknownMessageType = errors.New("unknown type")
Expand Down
2 changes: 1 addition & 1 deletion p2p/client.go
Expand Up @@ -175,7 +175,7 @@ func (c *Client) SendHandshake(info *HandshakeInfo) (err error) {
if err != nil {
return
}
signature, err := ecc.NewSignature("EOS111111111111111111111111111111111111111111111111111111111111111111LHpNx")
signature, err := ecc.NewSignature("SIG_K1_K2WBNtiTY8o4mqFSz7HPnjkiT9JhUYGFa81RrzaXr3aWRF1F8qwVfutJXroqiL35ZiHTcvn8gPWGYJDwnKZTCcbAGJy4i9")
if err != nil {
return
}
Expand Down
12 changes: 2 additions & 10 deletions p2p_test.go
Expand Up @@ -84,12 +84,6 @@ func TestP2PMessage_DecodePayload(t *testing.T) {
ExpectedStruct: &SyncRequestMessage{},
ExpectedErr: false,
},
{
Name: "SignedBlockSummaryMessage Good",
HexString: "0f010000060003338e14a48fd745ae3ff9d9dfb3d149c04507f9fde929c67311e1f004eab21849e444b7d9a2e6e5730eef8166a57ef1cc6e905cc0944fd8cee5d0c2ec6ec9a53076333442d7a57ce7820187f8889111443a1466666eac707ece1249d91a1a279ee04a856013e6b1fc7a14d74d8c237d47d8e2d951c422301f77342eb6f79f143958c90000000000ea30550000000000001f7ed3ef0a9a8bc7b695a390b20909852a7c43e3e54dce9d64aa107762a0b54b904b611084d16fb2bb4973374f380bd43548ac8e64e52c9911bcbb96128ccf5a11010000010100010000000000ea30550000000000ea305501001326b7530160d3c85db322fd2c550248fe22151d1e9423d2250a699595e5b1c1517d",
ExpectedStruct: &SignedBlockSummaryMessage{},
ExpectedErr: false,
},
{
Name: "SignedBlockMessage Good",
HexString: "100100000700022373115ab1ff9296887bd50c09a767ec55e9af84773cfd3981c7771d66c67c20e1449dca75777f692ada89a117e359c078e13ff5c237b2d11e35b2d84b01eb92c712547d5ceae4a7bbc4ba2e17d86f8df6b3f6f336e6dc884eea726e1f6c68d72dd7b6454c4f04d4610ff2852993d0292d6022e2e3bba07c25d7a369276e01f1c3ed0000000000ea30550000000000002074f4a360736226aa1e0a14e7a11df65197c847e1054835d4229d806fb109b2f065791a1b9bcbfc2eefddab7bccc3e284cdacf28a2550072fc14b57c0f0bc7bc4010000010100010000000000ea30550000000000ea3055010013261ddcaa56f9d00f2a55ebbd28d5607c977e8e513554483891a8d4c0532c4b662e00",
Expand Down Expand Up @@ -166,9 +160,7 @@ func TestMessageType_Name(t *testing.T) {
{Type: NoticeMessageType, ExpectedName: "Notice", OK: true},
{Type: RequestMessageType, ExpectedName: "Request", OK: true},
{Type: SyncRequestMessageType, ExpectedName: "SyncRequest", OK: true},
{Type: SignedBlockSummaryMessageType, ExpectedName: "SignedBlockSummary", OK: true},
{Type: SignedBlockMessageType, ExpectedName: "SignedBlock", OK: true},
{Type: SignedTransactionMessageType, ExpectedName: "SignedTransaction", OK: true},
{Type: PackedTransactionMessageType, ExpectedName: "PackedTransaction", OK: true},
{Type: P2PMessageType(100), ExpectedName: "Unknown", OK: false},
}
Expand All @@ -188,7 +180,7 @@ func TestDecoder_P2PMessageEnvelope(t *testing.T) {

msg := &P2PMessageEnvelope{
Length: 4,
Type: SignedTransactionMessageType,
Type: PackedTransactionMessageType,
Payload: []byte{1, 2, 3},
}

Expand All @@ -202,7 +194,7 @@ func TestDecoder_P2PMessageEnvelope(t *testing.T) {
err = d.Decode(&decoded)
assert.NoError(t, err)
assert.Equal(t, uint32(4), decoded.Length)
assert.Equal(t, SignedTransactionMessageType, decoded.Type)
assert.Equal(t, PackedTransactionMessageType, decoded.Type)
assert.Equal(t, []byte{1, 2, 3}, decoded.Payload)
}

Expand Down
19 changes: 11 additions & 8 deletions p2ptypes.go
Expand Up @@ -36,6 +36,17 @@ func (m *HandshakeMessage) GetType() P2PMessageType {
return HandshakeMessageType
}

type ChainSizeMessage struct {
LastIrreversibleBlockNum uint32 `json:"last_irreversible_block_num"`
LastIrreversibleBlockID SHA256Bytes `json:"last_irreversible_block_id"`
//HeadNum uint32 `json:"head_num"`
//HeadID SHA256Bytes `json:"head_id"`
}

func (m *ChainSizeMessage) GetType() P2PMessageType {
return ChainSizeType
}

func (m *HandshakeMessage) String() string {
return fmt.Sprintf("Handshake: Head [%d] Last Irreversible [%d] Time [%s]", m.HeadNum, m.LastIrreversibleBlockNum, m.Time)
}
Expand Down Expand Up @@ -213,10 +224,6 @@ type SignedBlockSummaryMessage struct {
Regions []RegionSummary `json:"regions"`
}

func (m *SignedBlockSummaryMessage) GetType() P2PMessageType {
return SignedBlockSummaryMessageType
}

type SignedBlockMessage struct {
SignedBlockSummaryMessage
InputTransactions []PackedTransaction `json:"input_transactions"`
Expand Down Expand Up @@ -287,10 +294,6 @@ type SignedTransactionMessage struct {
ContextFreeData []byte `json:"context_free_data"`
}

func (m *SignedTransactionMessage) GetType() P2PMessageType {
return SignedTransactionMessageType
}

type PackedTransactionMessage struct {
PackedTransaction
}
Expand Down
28 changes: 18 additions & 10 deletions responses.go
Expand Up @@ -18,16 +18,24 @@ type InfoResp struct {
}

type BlockResp struct {
Previous string `json:"previous"` // : "0000007a9dde66f1666089891e316ac4cb0c47af427ae97f93f36a4f1159a194",
Timestamp JSONTime `json:"timestamp"` // : "2017-12-04T17:12:08",
TransactionMerkleRoot string `json:"transaction_merkle_root"` // : "0000000000000000000000000000000000000000000000000000000000000000",
Producer AccountName `json:"producer"` // : "initj",
ProducerChanges []ProducerChange `json:"producer_changes"` // : [],
ProducerSignature string `json:"producer_signature"` // : "203dbf00b0968bfc47a8b749bbfdb91f8362b27c3e148a8a3c2e92f42ec55e9baa45d526412c8a2fc0dd35b484e4262e734bea49000c6f9c8dbac3d8861c1386c0",
Cycles []Cycle `json:"cycles"` // : [],
ID string `json:"id"` // : "0000007b677719bdd76d729c3ac36bed5790d5548aadc26804489e5e179f4a5b",
BlockNum uint64 `json:"block_num"` // : 123,
RefBlockPrefix uint64 `json:"ref_block_prefix"` // : 2624744919
Previous string `json:"previous"` // : "0000007a9dde66f1666089891e316ac4cb0c47af427ae97f93f36a4f1159a194",
Timestamp JSONTime `json:"timestamp"` // : "2017-12-04T17:12:08",
TransactionMerkleRoot string `json:"transaction_merkle_root"` // : "0000000000000000000000000000000000000000000000000000000000000000",
Producer AccountName `json:"producer"` // : "initj",
ProducerChanges []ProducerChange `json:"producer_changes"` // : [],
ProducerSignature string `json:"producer_signature"` // : "203dbf00b0968bfc47a8b749bbfdb91f8362b27c3e148a8a3c2e92f42ec55e9baa45d526412c8a2fc0dd35b484e4262e734bea49000c6f9c8dbac3d8861c1386c0",
Cycles []Cycle `json:"cycles"` // : [],
ID string `json:"id"` // : "0000007b677719bdd76d729c3ac36bed5790d5548aadc26804489e5e179f4a5b",
BlockNum uint64 `json:"block_num"` // : 123,
RefBlockPrefix uint64 `json:"ref_block_prefix"` // : 2624744919
Transactions []BlockTransaction `json:"transactions"`
}

type BlockTransaction struct {
Status string `json:"status"`
CPUUsageUS int `json:"cpu_usage_us"`
NetUsageWords int `json:"net_usage_words"`
Trx []json.RawMessage `json:"trx"`
}

type TransactionResp struct {
Expand Down
26 changes: 14 additions & 12 deletions types_test.go
Expand Up @@ -163,18 +163,20 @@ func TestNameToString(t *testing.T) {
in string
out string
}{
{"0000001e4d75af46", "currency"},
{"0000000000ea3055", "eosio"},
{"00409e9a2264b89a", "newaccount"},
{"00000003884ed1c9", "tbcox2.3"},
{"00000000a8ed3232", "active"},
{"000000572d3ccdcd", "transfer"},
{"00000059b1abe931", "abourget"},
{"c08fca86a9a8d2d4", "undelegatebw"},
{"0040cbdaa86c52d5", "updateauth"},
{"0000000080ab26a7", "owner"},
{"00000040258ab2c2", "setcode"},
{"00000000b863b2c2", "setabi"},
//{"0000001e4d75af46", "currency"},
//{"0000000000ea3055", "eosio"},
//{"00409e9a2264b89a", "newaccount"},
//{"00000003884ed1c9", "tbcox2.3"},
//{"00000000a8ed3232", "active"},
//{"000000572d3ccdcd", "transfer"},
//{"00000059b1abe931", "abourget"},
//{"c08fca86a9a8d2d4", "undelegatebw"},
//{"0040cbdaa86c52d5", "updateauth"},
//{"0000000080ab26a7", "owner"},
//{"00000040258ab2c2", "setcode"},
//{"00000000b863b2c2", "setabi"},
//{"00000000b863b2c2", "setabi"},
{"90803bea9ab83055", "eosflarebios"},
}

for _, test := range tests {
Expand Down

0 comments on commit 1fecc00

Please sign in to comment.