Skip to content

Commit

Permalink
Support ICON extension for replay task
Browse files Browse the repository at this point in the history
  • Loading branch information
mksong76 committed Sep 22, 2023
1 parent 525e5a8 commit 6f49d8d
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
11 changes: 11 additions & 0 deletions icon/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/icon-project/goloop/icon/iiss/icutils"
"github.com/icon-project/goloop/icon/merkle/hexary"
"github.com/icon-project/goloop/module"
"github.com/icon-project/goloop/service"
"github.com/icon-project/goloop/service/contract"
"github.com/icon-project/goloop/service/platform/basic"
"github.com/icon-project/goloop/service/state"
Expand Down Expand Up @@ -308,3 +309,13 @@ func (p *platform) getExtensionState(wc state.WorldContext, logger log.Logger) *
}
return esi
}


func (p *platform) ShowDiff(ctx service.DiffContext, name string, e, r []byte) error {
switch name {
case service.DNExtension:
return ShowExtensionDiff(ctx, e, r)
default:
return errors.IllegalArgumentError.Errorf("UnknownObject(name=%s)", name)
}
}
74 changes: 74 additions & 0 deletions icon/showextensiondiff.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package icon

import (
"bytes"

"github.com/icon-project/goloop/common"
"github.com/icon-project/goloop/common/codec"
"github.com/icon-project/goloop/icon/iiss/icobject"
"github.com/icon-project/goloop/icon/iiss/icreward"
"github.com/icon-project/goloop/icon/iiss/icstage"
"github.com/icon-project/goloop/icon/iiss/icstate"
"github.com/icon-project/goloop/service"
)

type ExtensionValues struct {
State common.HexBytes `json:"state"`
Front common.HexBytes `json:"front"`
Back common.HexBytes `json:"back"`
Back2 common.HexBytes `json:"back2"`
Reward common.HexBytes `json:"reward"`
}

func ShowExtensionDiff(c service.DiffContext, e, r []byte) error {
var ev, rv ExtensionValues
_, err := codec.BC.UnmarshalFromBytes(e, &ev)
if err != nil {
return err
}
_, err = codec.BC.UnmarshalFromBytes(r, &rv)
if err != nil {
return err
}
if !bytes.Equal(ev.State.Bytes(), rv.State.Bytes()) {
tdb := icobject.AttachObjectFactory(c.Database(), icstate.NewObjectImpl)
err := c.ShowObjectMPTDiff("ext.state", tdb, icobject.ObjectType,
ev.State.Bytes(), rv.State.Bytes(), nil)
if err != nil {
return err
}
}
if !bytes.Equal(ev.Front.Bytes(), rv.Front.Bytes()) {
tdb := icobject.AttachObjectFactory(c.Database(), icstage.NewObjectImpl)
err := c.ShowObjectMPTDiff("ext.front", tdb, icobject.ObjectType,
ev.Front.Bytes(), rv.Front.Bytes(), nil)
if err != nil {
return err
}
}
if !bytes.Equal(ev.Back.Bytes(), rv.Back.Bytes()) {
tdb := icobject.AttachObjectFactory(c.Database(), icstage.NewObjectImpl)
err := c.ShowObjectMPTDiff("ext.back", tdb, icobject.ObjectType,
ev.Back.Bytes(), rv.Back.Bytes(), nil)
if err != nil {
return err
}
}
if !bytes.Equal(ev.Back2.Bytes(), rv.Back2.Bytes()) {
tdb := icobject.AttachObjectFactory(c.Database(), icstage.NewObjectImpl)
err := c.ShowObjectMPTDiff("ext.back2", tdb, icobject.ObjectType,
ev.Back2.Bytes(), rv.Back2.Bytes(), nil)
if err != nil {
return err
}
}
if !bytes.Equal(ev.Reward.Bytes(), rv.Reward.Bytes()) {
tdb := icobject.AttachObjectFactory(c.Database(), icreward.NewObjectImpl)
err := c.ShowObjectMPTDiff("ext.reward", tdb, icobject.ObjectType,
ev.Reward.Bytes(), rv.Reward.Bytes(), nil)
if err != nil {
return err
}
}
return nil
}

0 comments on commit 6f49d8d

Please sign in to comment.