Skip to content

Commit

Permalink
Merge pull request #2 from rarimo/fix/near-provider-figure
Browse files Browse the repository at this point in the history
update near-go version, fix dockerfile
  • Loading branch information
napalmpapalam authored Oct 10, 2023
2 parents 56b8d13 + e277bd2 commit b6748bc
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 28 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM golang:1.20-alpine as buildbase

WORKDIR /go/src/github.com/rarimo/near-saver-svc
RUN apk add build-base
COPY vendor .
COPY . .

Expand Down
13 changes: 12 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/alecthomas/kingpin v2.2.6+incompatible
github.com/ethereum/go-ethereum v1.10.26
github.com/gogo/protobuf v1.3.3
github.com/rarimo/near-go v0.0.0-20231005083452-a6a5e72cf5ef
github.com/rarimo/near-go v0.0.0-20231010092111-60a68fb20b8b
github.com/rarimo/rarimo-core v0.0.0-20231004143803-6b209428ecbf
github.com/rarimo/saver-grpc-lib v1.0.0
github.com/tendermint/tendermint v0.34.27
Expand All @@ -27,6 +27,7 @@ require (
github.com/99designs/keyring v1.2.1 // indirect
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d // indirect
github.com/Masterminds/squirrel v1.4.0 // indirect
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
Expand All @@ -36,6 +37,7 @@ require (
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/blendle/zapdriver v1.3.1 // indirect
github.com/btcsuite/btcd v0.23.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/confio/ics23/go v0.9.0 // indirect
Expand All @@ -48,6 +50,8 @@ require (
github.com/cosmos/ledger-cosmos-go v0.12.2 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set v1.8.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/dfuse-io/logging v0.0.0-20210109005628-b97a57253f70 // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
github.com/dgraph-io/ristretto v0.1.0 // indirect
Expand All @@ -63,7 +67,9 @@ require (
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/golang/glog v1.1.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand Down Expand Up @@ -117,6 +123,7 @@ require (
github.com/rarimo/broadcaster-svc v1.0.2 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
Expand All @@ -135,8 +142,11 @@ require (
github.com/tidwall/gjson v1.14.4 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tklauser/go-sysconf v0.3.10 // indirect
github.com/tklauser/numcpus v0.4.0 // indirect
github.com/zondax/hid v0.9.1 // indirect
github.com/zondax/ledger-go v0.14.1 // indirect
gitlab.com/distributed_lab/figure/v3 v3.1.3 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
go.opencensus.io v0.24.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
Expand All @@ -152,6 +162,7 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/uint128 v1.2.0 // indirect
Expand Down
53 changes: 51 additions & 2 deletions go.sum

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions internal/services/saver/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

type messageGetter interface {
GetMessage(ctx context.Context, event *common.BridgeEventData) (*oracletypes.MsgCreateTransferOp, error)
GetMessage(ctx context.Context, event *common.BridgeDepositedEventData) (*oracletypes.MsgCreateTransferOp, error)
}

type txProcessor struct {
Expand All @@ -29,14 +29,14 @@ func newTxProcessor(cfg config.Config) *txProcessor {
contract: cfg.ListenConf().Contract,
broadcaster: cfg.Broadcaster(),
operators: map[common.BridgeEventType]messageGetter{
common.NativeEventType: voter.NewNativeOperator(cfg.ListenConf().Chain, cfg.Cosmos(), cfg.Log()),
common.FTEventType: voter.NewFTOperator(cfg.ListenConf().Chain, cfg.Cosmos(), cfg.Log()),
common.NFTEventType: voter.NewNFTOperator(cfg.ListenConf().Chain, cfg.Cosmos(), cfg.Near(), cfg.Log()),
common.EventTypeNativeDeposited: voter.NewNativeOperator(cfg.ListenConf().Chain, cfg.Cosmos(), cfg.Log()),
common.EventTypeFTDeposited: voter.NewFTOperator(cfg.ListenConf().Chain, cfg.Cosmos(), cfg.Log()),
common.EventTypeNFTDeposited: voter.NewNFTOperator(cfg.ListenConf().Chain, cfg.Cosmos(), cfg.Near(), cfg.Log()),
},
}
}

func (t *txProcessor) ProcessTx(ctx context.Context, tx, eventID string, event *common.BridgeEvent) error {
func (t *txProcessor) ProcessTx(ctx context.Context, tx, eventID string, event *common.BridgeDepositedEvent) error {
t.log.Debug("Parsing transaction " + tx)

operator, ok := t.operators[common.BridgeEventType(event.Event)]
Expand Down
2 changes: 1 addition & 1 deletion internal/services/voter/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
oracletypes "github.com/rarimo/rarimo-core/x/oraclemanager/types"
)

func appendBundleIfExists(msg *oracletypes.MsgCreateTransferOp, event *common.BridgeEventData) *oracletypes.MsgCreateTransferOp {
func appendBundleIfExists(msg *oracletypes.MsgCreateTransferOp, event *common.BridgeDepositedEventData) *oracletypes.MsgCreateTransferOp {
if event.BundleData != nil && len(*event.BundleData) > 0 && event.BundleSalt != nil && len(*event.BundleSalt) > 0 {
msg.BundleData = *event.BundleData
msg.BundleSalt = *event.BundleSalt
Expand Down
6 changes: 3 additions & 3 deletions internal/services/voter/equaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

type messageGetter interface {
GetMessage(ctx context.Context, event *common.BridgeEventData) (*oracletypes.MsgCreateTransferOp, error)
GetMessage(ctx context.Context, event *common.BridgeDepositedEventData) (*oracletypes.MsgCreateTransferOp, error)
}

type equaler struct {
Expand All @@ -25,7 +25,7 @@ func newEqualer(core *coreProvider) *equaler {
}
}

func (e *equaler) CheckEquality(ctx context.Context, operator messageGetter, event *common.BridgeEvent, transfer *rarimotypes.Transfer) error {
func (e *equaler) CheckEquality(ctx context.Context, operator messageGetter, event *common.BridgeDepositedEvent, transfer *rarimotypes.Transfer) error {
eventData := event.Data[0]
msg, err := operator.GetMessage(ctx, &eventData)
if err != nil {
Expand All @@ -40,7 +40,7 @@ func (e *equaler) CheckEquality(ctx context.Context, operator messageGetter, eve
}

// if its NFT event, we need to verify seed
if common.BridgeEventType(event.Event) == common.NFTEventType && transfer.Meta != nil {
if common.BridgeEventType(event.Event) == common.EventTypeNFTDeposited && transfer.Meta != nil {
msg.Meta.Seed = transfer.Meta.Seed
msg.To.TokenID = transfer.To.TokenID

Expand Down
12 changes: 6 additions & 6 deletions internal/services/voter/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ var eventPrefix = "EVENT_JSON:"

var ErrEventNotFound = errors.New("event not found")

func extractEvent(tx *common.FinalExecutionOutcomeWithReceiptView, contractAddr, eventID string) (*common.BridgeEvent, error) {
var event *common.BridgeEvent
func extractEvent(tx *common.FinalExecutionOutcomeWithReceiptView, contractAddr, eventID string) (*common.BridgeDepositedEvent, error) {
var event *common.BridgeDepositedEvent

for _, receiptOutcome := range tx.FinalExecutionOutcomeView.ReceiptsOutcome {
// Skipping receipt if it's not related to the contract
Expand Down Expand Up @@ -40,13 +40,13 @@ func extractEvent(tx *common.FinalExecutionOutcomeWithReceiptView, contractAddr,
return event, nil
}

func GetEventFromLog(log string) *common.BridgeEvent {
func GetEventFromLog(log string) *common.BridgeDepositedEvent {
if !strings.HasPrefix(log, eventPrefix) {
return nil
}

eventRaw := strings.TrimPrefix(log, eventPrefix)
var event common.BridgeEvent
var event common.BridgeDepositedEvent

err := json.Unmarshal([]byte(eventRaw), &event)
if err != nil {
Expand All @@ -61,9 +61,9 @@ func GetEventFromLog(log string) *common.BridgeEvent {
return &event
}

func validateDepositEvent(event common.BridgeEvent) bool {
func validateDepositEvent(event common.BridgeDepositedEvent) bool {
switch common.BridgeEventType(event.Event) {
case common.NFTEventType, common.FTEventType, common.NativeEventType:
case common.EventTypeNFTDeposited, common.EventTypeFTDeposited, common.EventTypeNativeDeposited:
return true
default:
return false
Expand Down
4 changes: 2 additions & 2 deletions internal/services/voter/t_ft.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ func NewFTOperator(chain string, rarimo *grpc.ClientConn, log *logan.Entry) *FTO
// Implements txParser
var _ txParser = &FTOperator{}

func (f *FTOperator) ParseTransaction(ctx context.Context, event *common.BridgeEvent, transfer *rarimotypes.Transfer) error {
func (f *FTOperator) ParseTransaction(ctx context.Context, event *common.BridgeDepositedEvent, transfer *rarimotypes.Transfer) error {
return f.equaler.CheckEquality(ctx, f, event, transfer)
}

func (f *FTOperator) GetMessage(ctx context.Context, event *common.BridgeEventData) (*oracletypes.MsgCreateTransferOp, error) {
func (f *FTOperator) GetMessage(ctx context.Context, event *common.BridgeDepositedEventData) (*oracletypes.MsgCreateTransferOp, error) {
from := tokentypes.OnChainItemIndex{
Chain: f.chain,
Address: hexutil.Encode([]byte(*event.Token)),
Expand Down
4 changes: 2 additions & 2 deletions internal/services/voter/t_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ func NewNativeOperator(chain string, rarimo *grpc.ClientConn, log *logan.Entry)
// Implements txParser
var _ txParser = &NativeOperator{}

func (n *NativeOperator) ParseTransaction(ctx context.Context, event *common.BridgeEvent, transfer *rarimotypes.Transfer) error {
func (n *NativeOperator) ParseTransaction(ctx context.Context, event *common.BridgeDepositedEvent, transfer *rarimotypes.Transfer) error {
return n.equaler.CheckEquality(ctx, n, event, transfer)
}

func (n *NativeOperator) GetMessage(ctx context.Context, event *common.BridgeEventData) (*oracletypes.MsgCreateTransferOp, error) {
func (n *NativeOperator) GetMessage(ctx context.Context, event *common.BridgeDepositedEventData) (*oracletypes.MsgCreateTransferOp, error) {
from := tokentypes.OnChainItemIndex{
Chain: n.chain,
Address: "",
Expand Down
4 changes: 2 additions & 2 deletions internal/services/voter/t_nft.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ func NewNFTOperator(chain string, rarimo *grpc.ClientConn, near nearprovider.Pro
// Implements txParser
var _ txParser = &NFTOperator{}

func (n *NFTOperator) ParseTransaction(ctx context.Context, event *common.BridgeEvent, transfer *rarimotypes.Transfer) error {
func (n *NFTOperator) ParseTransaction(ctx context.Context, event *common.BridgeDepositedEvent, transfer *rarimotypes.Transfer) error {
return n.equaler.CheckEquality(ctx, n, event, transfer)
}

func (n *NFTOperator) GetMessage(ctx context.Context, event *common.BridgeEventData) (*oracletypes.MsgCreateTransferOp, error) {
func (n *NFTOperator) GetMessage(ctx context.Context, event *common.BridgeDepositedEventData) (*oracletypes.MsgCreateTransferOp, error) {
addressFrom := hexutil.Encode([]byte(*event.Token))
tokenIdFrom := *event.TokenID

Expand Down
8 changes: 4 additions & 4 deletions internal/services/voter/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

type txParser interface {
ParseTransaction(ctx context.Context, event *common.BridgeEvent, transfer *rarimotypes.Transfer) error
ParseTransaction(ctx context.Context, event *common.BridgeDepositedEvent, transfer *rarimotypes.Transfer) error
}

type TransferOperator struct {
Expand All @@ -28,9 +28,9 @@ func NewTransferOperator(cfg config.Config) *TransferOperator {
contract: cfg.ListenConf().Contract,
chain: cfg.ListenConf().Chain,
txParsers: map[common.BridgeEventType]txParser{
common.NativeEventType: NewNativeOperator(cfg.ListenConf().Chain, cfg.Cosmos(), cfg.Log()),
common.FTEventType: NewFTOperator(cfg.ListenConf().Chain, cfg.Cosmos(), cfg.Log()),
common.NFTEventType: NewNFTOperator(cfg.ListenConf().Chain, cfg.Cosmos(), cfg.Near(), cfg.Log()),
common.EventTypeNFTDeposited: NewNFTOperator(cfg.ListenConf().Chain, cfg.Cosmos(), cfg.Near(), cfg.Log()),
common.EventTypeFTDeposited: NewFTOperator(cfg.ListenConf().Chain, cfg.Cosmos(), cfg.Log()),
common.EventTypeNativeDeposited: NewNativeOperator(cfg.ListenConf().Chain, cfg.Cosmos(), cfg.Log()),
},
}
}
Expand Down

0 comments on commit b6748bc

Please sign in to comment.