Skip to content

Commit

Permalink
resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
jimjbrettj committed Jul 8, 2021
2 parents e4e92f9 + 1916f86 commit 4fa855c
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 258 deletions.
7 changes: 4 additions & 3 deletions dot/core/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/ChainSafe/gossamer/lib/crypto/sr25519"
"github.com/ChainSafe/gossamer/lib/keystore"
"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/lib/scale"
"github.com/ChainSafe/gossamer/pkg/scale"

"github.com/centrifuge/go-substrate-rpc-client/v3/signature"
ctypes "github.com/centrifuge/go-substrate-rpc-client/v3/types"
Expand All @@ -42,11 +42,12 @@ func createExtrinsic(t *testing.T, rt runtime.Instance, genHash common.Hash, non
rawMeta, err := rt.Metadata()
require.NoError(t, err)

decoded, err := scale.Decode(rawMeta, []byte{})
var decoded []byte
err = scale.Unmarshal(rawMeta, &decoded)
require.NoError(t, err)

meta := &ctypes.Metadata{}
err = ctypes.DecodeFromBytes(decoded.([]byte), meta)
err = ctypes.DecodeFromBytes(decoded, meta)
require.NoError(t, err)

rv, err := rt.Version()
Expand Down
4 changes: 2 additions & 2 deletions dot/core/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import (
"github.com/ChainSafe/gossamer/lib/keystore"
"github.com/ChainSafe/gossamer/lib/runtime"
rtstorage "github.com/ChainSafe/gossamer/lib/runtime/storage"
"github.com/ChainSafe/gossamer/lib/scale"
"github.com/ChainSafe/gossamer/lib/services"
"github.com/ChainSafe/gossamer/lib/transaction"
"github.com/ChainSafe/gossamer/pkg/scale"
log "github.com/ChainSafe/log15"
)

Expand Down Expand Up @@ -431,7 +431,7 @@ func (s *Service) handleChainReorg(prev, curr common.Hash) error {
// currently we are attempting to re-add inherents, causing lots of "'Bad input data provided to validate_transaction" errors.
for _, ext := range exts {
logger.Debug("validating transaction on re-org chain", "extrinsic", ext)
encExt, err := scale.Encode(ext)
encExt, err := scale.Marshal(ext)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions dot/network/stream_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ func TestStreamManager(t *testing.T) {

time.Sleep(cleanupStreamInterval * 2)
connsAToB := ha.Network().ConnsToPeer(hb.ID())
require.Equal(t, 1, len(connsAToB))
require.GreaterOrEqual(t, len(connsAToB), 1)
require.Equal(t, 0, len(connsAToB[0].GetStreams()))

connsBToA := hb.Network().ConnsToPeer(ha.ID())
require.Equal(t, 1, len(connsBToA))
require.GreaterOrEqual(t, len(connsBToA), 1)
require.Equal(t, 0, len(connsBToA[0].GetStreams()))
}

Expand All @@ -91,12 +91,12 @@ func TestStreamManager_KeepStream(t *testing.T) {
smA.start()
smB.start()

time.Sleep(cleanupStreamInterval / 2)
time.Sleep(cleanupStreamInterval / 3)
connsAToB := ha.Network().ConnsToPeer(hb.ID())
require.Equal(t, 1, len(connsAToB))
require.GreaterOrEqual(t, len(connsAToB), 1)
require.Equal(t, 1, len(connsAToB[0].GetStreams()))

connsBToA := hb.Network().ConnsToPeer(ha.ID())
require.Equal(t, 1, len(connsBToA))
require.GreaterOrEqual(t, len(connsBToA), 1)
require.Equal(t, 1, len(connsBToA[0].GetStreams()))
}
16 changes: 11 additions & 5 deletions dot/rpc/modules/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,18 @@ func setupSystemModule(t *testing.T) *SystemModule {
Nonce: 3,
//RefCount: 0,
Data: struct {
Free common.Uint128
Reserved common.Uint128
MiscFrozen common.Uint128
FreeFrozen common.Uint128
}{},
Free *scale.Uint128
Reserved *scale.Uint128
MiscFrozen *scale.Uint128
FreeFrozen *scale.Uint128
}{
Free: scale.MustNewUint128(big.NewInt(0)),
Reserved: scale.MustNewUint128(big.NewInt(0)),
MiscFrozen: scale.MustNewUint128(big.NewInt(0)),
FreeFrozen: scale.MustNewUint128(big.NewInt(0)),
},
}

aliceAcctEncoded, err := scale.Marshal(aliceAcctInfo)
require.NoError(t, err)
ts.Set(aliceAcctStoKey, aliceAcctEncoded)
Expand Down
10 changes: 5 additions & 5 deletions dot/types/account.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package types

import (
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/pkg/scale"
)

// AccountInfo Information of an account.
Expand All @@ -12,9 +12,9 @@ type AccountInfo struct {
Producers uint32
// The additional data that belongs to this account. Used to store the balance(s) in a lot of chains.
Data struct {
Free common.Uint128
Reserved common.Uint128
MiscFrozen common.Uint128
FreeFrozen common.Uint128
Free *scale.Uint128
Reserved *scale.Uint128
MiscFrozen *scale.Uint128
FreeFrozen *scale.Uint128
}
}
77 changes: 49 additions & 28 deletions lib/genesis/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"log"
"math/big"
"path/filepath"
"reflect"
Expand All @@ -32,8 +33,8 @@ import (
"github.com/ChainSafe/gossamer/lib/crypto/ed25519"
"github.com/ChainSafe/gossamer/lib/crypto/sr25519"
"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/lib/scale"
"github.com/ChainSafe/gossamer/lib/trie"
"github.com/ChainSafe/gossamer/pkg/scale"
)

// NewGenesisFromJSONRaw parses a JSON formatted genesis file
Expand Down Expand Up @@ -161,10 +162,13 @@ func buildRawMap(m map[string]map[string]interface{}) (map[string]string, error)
for k, v := range m {
kv := new(keyValue)
kv.key = append(kv.key, k)
buildRawMapInterface(v, kv)
err := buildRawMapInterface(v, kv)
if err != nil {
return nil, err
}

if reflect.DeepEqual([]string{"palletBalances", "balances"}, kv.key) {
err := buildBalances(kv, res)
err = buildBalances(kv, res)
if err != nil {
return nil, err
}
Expand All @@ -187,36 +191,46 @@ func buildRawMap(m map[string]map[string]interface{}) (map[string]string, error)
return res, nil
}

func buildRawMapInterface(m map[string]interface{}, kv *keyValue) {
func buildRawMapInterface(m map[string]interface{}, kv *keyValue) error {
for k, v := range m {
kv.key = append(kv.key, k)
switch v2 := v.(type) {
case []interface{}:
kv.valueLen = big.NewInt(int64(len(v2)))
buildRawArrayInterface(v2, kv)
err := buildRawArrayInterface(v2, kv)
if err != nil {
return err
}
case string:
kv.value = v2
}
}
return nil
}

func buildRawArrayInterface(a []interface{}, kv *keyValue) {
func buildRawArrayInterface(a []interface{}, kv *keyValue) error {
for _, v := range a {
switch v2 := v.(type) {
case []interface{}:
buildRawArrayInterface(v2, kv)
err := buildRawArrayInterface(v2, kv)
if err != nil {
return err
}
case string:
// todo check to confirm it's an address
tba := crypto.PublicAddressToByteArray(common.Address(v2))
kv.value = kv.value + fmt.Sprintf("%x", tba)
kv.iVal = append(kv.iVal, tba)
case float64:
// TODO: determine how to handle this error
encVal, _ := scale.Encode(uint64(v2))
encVal, err := scale.Marshal(uint64(v2))
if err != nil {
return err
}
kv.value = kv.value + fmt.Sprintf("%x", encVal)
kv.iVal = append(kv.iVal, big.NewInt(int64(v2)))
}
}
return nil
}

func formatKey(kv *keyValue) (string, error) {
Expand Down Expand Up @@ -247,7 +261,7 @@ func formatValue(kv *keyValue) (string, error) {
switch {
case reflect.DeepEqual([]string{"grandpa", "authorities"}, kv.key):
if kv.valueLen != nil {
lenEnc, err := scale.Encode(kv.valueLen)
lenEnc, err := scale.Marshal(kv.valueLen)
if err != nil {
return "", err
}
Expand All @@ -259,7 +273,7 @@ func formatValue(kv *keyValue) (string, error) {
return kv.value, nil
default:
if kv.valueLen != nil {
lenEnc, err := scale.Encode(kv.valueLen)
lenEnc, err := scale.Marshal(kv.valueLen)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -287,19 +301,19 @@ func buildBalances(kv *keyValue, res map[string]string) error {
Nonce: 0,
//RefCount: 0,
Data: struct {
Free common.Uint128
Reserved common.Uint128
MiscFrozen common.Uint128
FreeFrozen common.Uint128
Free *scale.Uint128
Reserved *scale.Uint128
MiscFrozen *scale.Uint128
FreeFrozen *scale.Uint128
}{
Free: *common.Uint128FromBigInt(kv.iVal[i+1].(*big.Int)),
Reserved: *common.Uint128FromBigInt(big.NewInt(0)),
MiscFrozen: *common.Uint128FromBigInt(big.NewInt(0)),
FreeFrozen: *common.Uint128FromBigInt(big.NewInt(0)),
Free: scale.MustNewUint128(kv.iVal[i+1].(*big.Int)),
Reserved: scale.MustNewUint128(big.NewInt(0)),
MiscFrozen: scale.MustNewUint128(big.NewInt(0)),
FreeFrozen: scale.MustNewUint128(big.NewInt(0)),
},
}

encBal, err := scale.Encode(accInfo)
encBal, err := scale.Marshal(accInfo)
if err != nil {
return err
}
Expand Down Expand Up @@ -360,34 +374,41 @@ func addAuthoritiesValues(k1, k2 string, kt crypto.KeyType, value []byte, gen *G

// decode authorities values into []interface that will be decoded into json array
ava := [][]interface{}{}
buf := &bytes.Buffer{}
sd := scale.Decoder{Reader: buf}
_, err := buf.Write(value)
reader := new(bytes.Buffer)
_, err := reader.Write(value)
if err != nil {
return err
}

alen, err := sd.DecodeInteger()
var alen int
err = scale.Unmarshal(value, &alen)
if err != nil {
return err
}
for i := 0; i < int(alen); i++ {
for i := 0; i < alen; i++ {
auth := []interface{}{}
buf := make([]byte, 32)
if _, err = sd.Reader.Read(buf); err == nil {
if _, err = reader.Read(buf); err == nil {
var arr = [32]byte{}
copy(arr[:], buf)
//nolint
pa, err := bytesToAddress(kt, arr[:])
if err != nil {
return err
}
auth = append(auth, pa)
}
iv, err := sd.DecodeFixedWidthInt(uint64(0))
b := make([]byte, 8)
if _, err = reader.Read(b); err != nil {
log.Fatal(err)
}
var iv uint64
err = scale.Unmarshal(b, &iv)

if err != nil {
return err
}
auth = append(auth, iv.(uint64))
auth = append(auth, iv)
ava = append(ava, auth)
}

Expand Down
Loading

0 comments on commit 4fa855c

Please sign in to comment.