forked from centrifuge/go-substrate-rpc-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from centrifuge/master
Update fork with parent repository
- Loading branch information
Showing
31 changed files
with
878 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ dist: xenial | |
language: go | ||
|
||
go: | ||
- 1.11.x | ||
- 1.14.x | ||
|
||
# Only clone the most recent commit. | ||
git: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/centrifuge/go-substrate-rpc-client/scale" | ||
) | ||
|
||
type BalanceStatus byte | ||
|
||
const ( | ||
// Funds are free, as corresponding to `free` item in Balances. | ||
Free BalanceStatus = 0 | ||
// Funds are reserved, as corresponding to `reserved` item in Balances. | ||
Reserved BalanceStatus = 1 | ||
) | ||
|
||
func (bs *BalanceStatus) Decode(decoder scale.Decoder) error { | ||
b, err := decoder.ReadOneByte() | ||
vb := BalanceStatus(b) | ||
switch vb { | ||
case Free, Reserved: | ||
*bs = vb | ||
default: | ||
return fmt.Errorf("unknown BalanceStatus enum: %v", vb) | ||
} | ||
return err | ||
} | ||
|
||
func (bs BalanceStatus) Encode(encoder scale.Encoder) error { | ||
return encoder.PushByte(byte(bs)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package types | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/centrifuge/go-substrate-rpc-client/scale" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestBalanceStatusEncodeDecode(t *testing.T) { | ||
// encode | ||
bs := Reserved | ||
var buf bytes.Buffer | ||
encoder := scale.NewEncoder(&buf) | ||
assert.NoError(t, encoder.Encode(bs)) | ||
assert.Equal(t, buf.Len(), 1) | ||
assert.Equal(t, buf.Bytes(), []byte{1}) | ||
|
||
//decode | ||
decoder := scale.NewDecoder(bytes.NewReader(buf.Bytes())) | ||
bs0 := BalanceStatus(0) | ||
err := decoder.Decode(&bs0) | ||
assert.NoError(t, err) | ||
assert.Equal(t, bs0, Reserved) | ||
|
||
//decode error | ||
decoder = scale.NewDecoder(bytes.NewReader([]byte{5})) | ||
bs0 = BalanceStatus(0) | ||
err = decoder.Decode(&bs0) | ||
assert.Error(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/centrifuge/go-substrate-rpc-client/scale" | ||
) | ||
|
||
type ElectionCompute byte | ||
|
||
const ( | ||
// Result was forcefully computed on chain at the end of the session. | ||
OnChain ElectionCompute = 0 | ||
// Result was submitted and accepted to the chain via a signed transaction. | ||
Signed ElectionCompute = 1 | ||
// Result was submitted and accepted to the chain via an unsigned transaction (by an authority). | ||
Unsigned ElectionCompute = 2 | ||
) | ||
|
||
func (ec *ElectionCompute) Decode(decoder scale.Decoder) error { | ||
b, err := decoder.ReadOneByte() | ||
vb := ElectionCompute(b) | ||
switch vb { | ||
case OnChain, Signed, Unsigned: | ||
*ec = vb | ||
default: | ||
return fmt.Errorf("unknown ElectionCompute enum: %v", vb) | ||
} | ||
return err | ||
} | ||
|
||
func (ec ElectionCompute) Encode(encoder scale.Encoder) error { | ||
return encoder.PushByte(byte(ec)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package types | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/centrifuge/go-substrate-rpc-client/scale" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestElectionComputeEncodeDecode(t *testing.T) { | ||
// encode | ||
ec := OnChain | ||
var buf bytes.Buffer | ||
encoder := scale.NewEncoder(&buf) | ||
assert.NoError(t, encoder.Encode(ec)) | ||
assert.Equal(t, buf.Len(), 1) | ||
assert.Equal(t, buf.Bytes(), []byte{0}) | ||
|
||
//decode | ||
decoder := scale.NewDecoder(bytes.NewReader(buf.Bytes())) | ||
ec0 := ElectionCompute(0) | ||
err := decoder.Decode(&ec0) | ||
assert.NoError(t, err) | ||
assert.Equal(t, ec0, OnChain) | ||
|
||
//decode error | ||
decoder = scale.NewDecoder(bytes.NewReader([]byte{5})) | ||
ec0 = ElectionCompute(0) | ||
err = decoder.Decode(&ec0) | ||
assert.Error(t, err) | ||
} |
Oops, something went wrong.