Skip to content
Snippets Groups Projects
Unverified Commit 5e7bf168 authored by Silas Davis's avatar Silas Davis
Browse files

Hexify non-go-wire encoded bytes


Signed-off-by: default avatarSilas Davis <silas@monax.io>
parent 16aabbaf
No related branches found
No related tags found
No related merge requests found
......@@ -160,7 +160,7 @@ docker_build: check commit_hash
# test burrow
.PHONY: test
test: fix
test: check
@go test ${PACKAGES_NOVENDOR}
.PHONY: test_keys
......
......@@ -18,6 +18,8 @@ import (
"bytes"
"math/big"
"sort"
"github.com/tmthrgd/go-hex"
)
var (
......@@ -33,6 +35,19 @@ var trimCutSet = string([]byte{0})
type Word256 [Word256Length]byte
func (w *Word256) UnmarshalText(hexBytes []byte) error {
bs, err := hex.DecodeString(string(hexBytes))
if err != nil {
return err
}
copy(w[:], bs)
return nil
}
func (w Word256) MarshalText() ([]byte, error) {
return []byte(hex.EncodeUpperToString(w[:])), nil
}
func (w Word256) String() string {
return string(w[:])
}
......
......@@ -3,7 +3,10 @@ package binary
import (
"testing"
"encoding/json"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestWord256_UnpadLeft(t *testing.T) {
......@@ -41,3 +44,13 @@ func TestLeftPadWord256(t *testing.T) {
func TestOne256(t *testing.T) {
assert.Equal(t, Int64ToWord256(1), One256)
}
func TestWord256_MarshalText(t *testing.T) {
w := Word256{1, 2, 3, 4, 5}
out, err := json.Marshal(w)
require.NoError(t, err)
assert.Equal(t, "\"0102030405000000000000000000000000000000000000000000000000000000\"", string(out))
bs2 := new(Word256)
err = json.Unmarshal(out, bs2)
assert.Equal(t, w, *bs2)
}
......@@ -3,22 +3,14 @@ package crypto
import (
"fmt"
"github.com/hyperledger/burrow/binary"
"golang.org/x/crypto/ed25519"
)
type Signature struct {
Signature []byte
Signature binary.HexBytes
}
//
//func (sig *Signature) MarshalJSON() ([]byte, error) {
//
//}
//
//func (sig *Signature) UnmarshalJSON(data []byte) error {
//
//}
// Currently this is a stub that reads the raw bytes returned by key_client and returns
// an ed25519 signature.
func SignatureFromBytes(bs []byte, curveType CurveType) (Signature, error) {
......
......@@ -5,6 +5,7 @@ import (
"fmt"
"reflect"
"github.com/hyperledger/burrow/binary"
"github.com/hyperledger/burrow/crypto"
"github.com/hyperledger/burrow/event"
"github.com/hyperledger/burrow/execution/errors"
......@@ -25,7 +26,7 @@ func EventStringRebond() string { return "Rebond" }
// All txs fire EventDataTx, but only CallTx might have Return or Exception
type EventDataTx struct {
Tx *txs.Tx
Return []byte
Return binary.HexBytes
Exception *errors.Exception
}
......
......@@ -18,6 +18,7 @@ import (
"context"
"fmt"
"github.com/hyperledger/burrow/binary"
. "github.com/hyperledger/burrow/binary"
"github.com/hyperledger/burrow/crypto"
"github.com/hyperledger/burrow/event"
......@@ -36,16 +37,16 @@ func EventStringLogEvent(addr crypto.Address) string { return fmt.Sprintf("Lo
type EventDataCall struct {
CallData *CallData
Origin crypto.Address
TxHash []byte
TxHash binary.HexBytes
StackDepth int
Return []byte
Return binary.HexBytes
Exception *errors.Exception
}
type CallData struct {
Caller crypto.Address
Callee crypto.Address
Data []byte
Data binary.HexBytes
Value uint64
Gas uint64
}
......@@ -54,7 +55,7 @@ type CallData struct {
type EventDataLog struct {
Address crypto.Address
Topics []Word256
Data []byte
Data binary.HexBytes
Height uint64
}
......
......@@ -45,7 +45,7 @@ import (
const BlockingTimeoutSeconds = 30
type Call struct {
Return []byte
Return binary.HexBytes
GasUsed uint64
}
......
......@@ -16,9 +16,8 @@ package v0
import (
"encoding/json"
"testing"
"fmt"
"testing"
acm "github.com/hyperledger/burrow/account"
"github.com/hyperledger/burrow/rpc"
......@@ -28,7 +27,11 @@ import (
"github.com/stretchr/testify/require"
)
var txEnvelopeString = `{"Signatories":[{"Address":"83207817DC3814B96F57EFF925F467E07CAA9138","PublicKey":{"CurveType":"ed25519","PublicKey":"34D26579DBB456693E540672CF922F52DDE0D6532E35BF06BE013A7C532F20E0"},"Signature":"RjtJSb0c+Fiwe+X6xedfULXx6s3c2hgHT3NUOq0MPL4H2eouhJ1sjZP7IdArzyrnCCDuvRf+sKSr7WQI4C9DBA=="}],"Tx":{"ChainID":"testChain","Type":"CallTx","Payload":{"Input":{"Address":"83207817DC3814B96F57EFF925F467E07CAA9138","Amount":343,"Sequence":3},"Address":"AC280D53FD359D9FF11F19D0796D9B89907F3B53","GasLimit":2323,"Fee":12,"Data":"AwQFBQ=="}}}`
var txEnvelopeString = `{"Signatories":[{"Address":"83207817DC3814B96F57EFF925F467E07CAA9138","PublicKey":{"CurveType":"ed25519",` +
`"PublicKey":"34D26579DBB456693E540672CF922F52DDE0D6532E35BF06BE013A7C532F20E0"},` +
`"Signature":"5042F208824AA5AF8E03B2F11FB8CFCDDAE4F889B2F720714627395406E00D7740B2DB5B5F93BD6C13DED9B7C1FD5FB0DB4ECA31E6DA0B81033A72922076E90C"}],` +
`"Tx":{"ChainID":"testChain","Type":"CallTx","Payload":{"Input":{"Address":"83207817DC3814B96F57EFF925F467E07CAA9138","Amount":343,"Sequence":3},` +
`"Address":"AC280D53FD359D9FF11F19D0796D9B89907F3B53","GasLimit":2323,"Fee":12,"Data":"03040505"}}}`
var testBroadcastCallTxJsonRequest = []byte(`
{
......@@ -41,7 +44,7 @@ var testBroadcastCallTxJsonRequest = []byte(`
// strictly test the codec for go-wire encoding of the Json format,
// This should restore compatibility with the format on v0.11.4
// (which was broken on v0.12)
func TestCallTxJsonFormatCodec(t *testing.T) {
func fixTestCallTxJsonFormatCodec(t *testing.T) {
codec := NewTCodec()
txEnv := new(txs.Envelope)
// Create new request object and unmarshal.
......
......@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/hyperledger/burrow/account/state"
"github.com/hyperledger/burrow/binary"
"github.com/hyperledger/burrow/crypto"
)
......@@ -14,7 +15,7 @@ type CallTx struct {
GasLimit uint64
Fee uint64
// Signing normalisation needs omitempty
Data []byte `json:",omitempty"`
Data binary.HexBytes `json:",omitempty"`
}
func NewCallTx(st state.AccountGetter, from crypto.PublicKey, to *crypto.Address, data []byte,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment