Skip to content

Commit

Permalink
Phase enum has new field Initialization (#103)
Browse files Browse the repository at this point in the history
* Phase enum has new field 'Initialization'

* fix go-critic lints
  • Loading branch information
vgeddes authored and mikiquantum committed Dec 15, 2020
1 parent 6ec76ca commit 84ed6a9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
16 changes: 12 additions & 4 deletions types/event_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ type Phase struct {
IsApplyExtrinsic bool
AsApplyExtrinsic uint32
IsFinalization bool
IsInitialization bool
}

func (p *Phase) Decode(decoder scale.Decoder) error {
Expand All @@ -323,11 +324,14 @@ func (p *Phase) Decode(decoder scale.Decoder) error {
return err
}

if b == 0 {
switch b {
case 0:
p.IsApplyExtrinsic = true
err = decoder.Decode(&p.AsApplyExtrinsic)
} else if b == 1 {
case 1:
p.IsFinalization = true
case 2:
p.IsInitialization = true
}

if err != nil {
Expand All @@ -339,11 +343,15 @@ func (p *Phase) Decode(decoder scale.Decoder) error {

func (p Phase) Encode(encoder scale.Encoder) error {
var err1, err2 error
if p.IsApplyExtrinsic {

switch {
case p.IsApplyExtrinsic:
err1 = encoder.PushByte(0)
err2 = encoder.Encode(p.AsApplyExtrinsic)
} else if p.IsFinalization {
case p.IsFinalization:
err1 = encoder.PushByte(1)
case p.IsInitialization:
err1 = encoder.PushByte(2)
}

if err1 != nil {
Expand Down
6 changes: 6 additions & 0 deletions types/event_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,9 @@ func TestDispatchError(t *testing.T) {
assertRoundtrip(t, DispatchError{HasModule: true, Module: 0xf1, Error: 0xa2})
assertRoundtrip(t, DispatchError{HasModule: false, Error: 0xa2})
}

func TestPhase(t *testing.T) {
assertRoundtrip(t, Phase{IsApplyExtrinsic: true, AsApplyExtrinsic: 43})
assertRoundtrip(t, Phase{IsFinalization: true})
assertRoundtrip(t, Phase{IsInitialization: true})
}

0 comments on commit 84ed6a9

Please sign in to comment.