mirror of
https://github.com/grassrootseconomics/cic-custodial.git
synced 2024-11-25 07:16:46 +01:00
41 lines
772 B
Go
41 lines
772 B
Go
package sub
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"github.com/grassrootseconomics/cic-custodial/internal/store"
|
|
"github.com/nats-io/nats.go"
|
|
)
|
|
|
|
func (s *Sub) handler(ctx context.Context, msg *nats.Msg) error {
|
|
var (
|
|
chainEvent store.MinimalTxInfo
|
|
)
|
|
|
|
if err := json.Unmarshal(msg.Data, &chainEvent); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := s.cu.PgStore.UpdateOtxStatusFromChainEvent(ctx, chainEvent); err != nil {
|
|
return err
|
|
}
|
|
|
|
switch msg.Subject {
|
|
case "CHAIN.register":
|
|
if chainEvent.Success {
|
|
if err := s.cu.PgStore.ActivateAccount(ctx, chainEvent.To); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
case "CHAIN.gas":
|
|
if chainEvent.Success {
|
|
if err := s.cu.PgStore.ResetGasQuota(ctx, chainEvent.To); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|