mirror of
https://github.com/grassrootseconomics/cic-custodial.git
synced 2024-11-30 01:06:46 +01:00
Mohamed Sohail
b9d3c219c8
NOTE: This needs the db to be nuked if you are running a test cluster * updated gas refilling logic to reflect EthFaucet contract * fully dependant on on-chain contract to refill and unlock gas * minor fixes to nonce bootstrapper Ideal Values: INITIAL GIFT = 0.015 THRESHOLD = 0.01 TIME = 12 * 60 * 60 # Sample for 30 txs EXTREME LOW = 0.00675 LOW GAS USAGE = 0.00694605 RISING = 0.0135 HIGH = 0.027
60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
package sub
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"github.com/nats-io/nats.go"
|
|
)
|
|
|
|
type (
|
|
ChainEvent struct {
|
|
Block uint64 `json:"block"`
|
|
From string `json:"from"`
|
|
To string `json:"to"`
|
|
ContractAddress string `json:"contractAddress"`
|
|
Success bool `json:"success"`
|
|
TxHash string `json:"transactionHash"`
|
|
TxIndex uint `json:"transactionIndex"`
|
|
Value uint64 `json:"value"`
|
|
}
|
|
)
|
|
|
|
func (s *Sub) processEventHandler(ctx context.Context, msg *nats.Msg) error {
|
|
var (
|
|
chainEvent ChainEvent
|
|
)
|
|
|
|
if err := json.Unmarshal(msg.Data, &chainEvent); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := s.cu.Store.UpdateDispatchStatus(
|
|
ctx,
|
|
chainEvent.Success,
|
|
chainEvent.TxHash,
|
|
chainEvent.Block,
|
|
); err != nil {
|
|
return err
|
|
}
|
|
|
|
if chainEvent.Success {
|
|
switch msg.Subject {
|
|
case "CHAIN.register":
|
|
if err := s.cu.Store.ActivateAccount(ctx, chainEvent.To); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := s.cu.Store.GasUnlock(ctx, chainEvent.To); err != nil {
|
|
return err
|
|
}
|
|
case "CHAIN.gas":
|
|
if err := s.cu.Store.GasUnlock(ctx, chainEvent.To); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|