Skip to content

Commit

Permalink
feat: retrive tx hash from mintCompleted event
Browse files Browse the repository at this point in the history
  • Loading branch information
sameh-farouk committed Nov 5, 2023
1 parent 5a0bd64 commit d7484ac
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bridge/tfchain_bridge/pkg/bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (bridge *Bridge) Start(ctx context.Context) error {
Msg("the bridge instance has exited unexpectedly")
}
}()
afterMinute := time.After(5 * time.Second)
afterMinute := time.After(60 * time.Second)

for {
select {
Expand Down
22 changes: 12 additions & 10 deletions bridge/tfchain_bridge/pkg/bridge/withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ func (bridge *Bridge) handleWithdrawCreated(ctx context.Context, withdraw subpkg
Msg("the withdraw transaction has already been processed")
return pkg.ErrTransactionAlreadyBurned
}

logger.Info().
Str("event_action", "transfer_initiated").
Str("event_kind", "event").
Str("category", "transfer").
Dict("metadata", zerolog.Dict().
Str("type", "burn")).
Msg("a transfer has initiated")

// check if it can hold tft : TODO check trust line TFT limit if it can receive the amount
if err := bridge.wallet.CheckAccount(withdraw.Target); err != nil {
return bridge.handleBadWithdraw(ctx, withdraw)
Expand All @@ -45,13 +54,6 @@ func (bridge *Bridge) handleWithdrawCreated(ctx context.Context, withdraw subpkg
if err != nil {
return nil
}
logger.Info().
Str("event_action", "transfer_initiated").
Str("event_kind", "event").
Str("category", "transfer").
Dict("metadata", zerolog.Dict().
Str("type", "burn")).
Msg("a transfer has initiated")

logger.Info().
Str("event_action", "withdraw_proposed").
Expand All @@ -68,7 +70,7 @@ func (bridge *Bridge) handleWithdrawCreated(ctx context.Context, withdraw subpkg
func (bridge *Bridge) handleWithdrawExpired(ctx context.Context, withdrawExpired subpkg.WithdrawExpiredEvent) error {
logger := log.Logger.With().Str("trace_id", fmt.Sprint(withdrawExpired.ID)).Logger()
if err := bridge.wallet.CheckAccount(withdrawExpired.Target); err != nil {
log.Warn().
logger.Warn().
Str("event_action", "transfer_failed").
Str("event_kind", "alert").
Str("category", "transfer").
Expand Down Expand Up @@ -111,7 +113,7 @@ func (bridge *Bridge) handleWithdrawExpired(ctx context.Context, withdrawExpired

func (bridge *Bridge) handleWithdrawReady(ctx context.Context, withdrawReady subpkg.WithdrawReadyEvent) error {
logger := log.Logger.With().Str("trace_id", fmt.Sprint(withdrawReady.ID)).Logger()

// ctx_with_trace_id := context.WithValue(ctx, "trace_id", fmt.Sprint(withdrawReady.ID))
burned, err := bridge.subClient.IsBurnedAlready(types.U64(withdrawReady.ID))
if err != nil {
return err
Expand All @@ -136,7 +138,7 @@ func (bridge *Bridge) handleWithdrawReady(ctx context.Context, withdrawReady sub
}

// todo add memo hash
err = bridge.wallet.CreatePaymentWithSignaturesAndSubmit(ctx, burnTx.Target, uint64(burnTx.Amount), "", burnTx.Signatures, int64(burnTx.SequenceNumber))
err = bridge.wallet.CreatePaymentWithSignaturesAndSubmit(ctx, burnTx.Target, uint64(burnTx.Amount), fmt.Sprint(withdrawReady.ID), burnTx.Signatures, int64(burnTx.SequenceNumber))
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions bridge/tfchain_bridge/pkg/substrate/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ func (client *SubstrateClient) processEventRecords(events *substrate.EventRecord
})
}

for range events.TFTBridgeModule_MintCompleted {
trace_id := "TODO" // TODO: GET tx id from the event. required tfchain runtime update
logger := log.Logger.With().Str("trace_id", trace_id).Logger()
for _, e := range events.TFTBridgeModule_MintCompleted {
trace_id := e.TxHash
logger := log.Logger.With().Str("trace_id", strings.TrimLeft(trace_id, "refund-")).Logger()
outcome := ""
if strings.HasPrefix(trace_id, "refund") {
outcome = "refunded"
Expand Down

0 comments on commit d7484ac

Please sign in to comment.