mirror of
https://github.com/grassrootseconomics/cic-custodial.git
synced 2024-11-23 14:46:45 +01:00
Mohammed Sohail
cf1f9f34c3
* fallback to custom ethereum checksum validator -> https://github.com/go-playground/validator/issues/1073 * decouple jetsream emitter to separate package * refactor task handlers into individual files * add error handler for echo to capture unexpected errors and log them * move handler dependencies into single struct container -> custodialContainer * replace signer to use EIP 1559 signer -> celoutils v1 * Add 1 minutes timeout to all custodial tasks
79 lines
1.6 KiB
Go
79 lines
1.6 KiB
Go
package task
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/grassrootseconomics/cic-custodial/internal/custodial"
|
|
"github.com/grassrootseconomics/cic-custodial/internal/events"
|
|
"github.com/grassrootseconomics/cic-custodial/internal/tasker"
|
|
"github.com/hibiken/asynq"
|
|
)
|
|
|
|
type AccountPayload struct {
|
|
PublicKey string `json:"publicKey"`
|
|
TrackingId string `json:"trackingId"`
|
|
}
|
|
|
|
func AccountPrepare(cu *custodial.Custodial) func(context.Context, *asynq.Task) error {
|
|
return func(ctx context.Context, t *asynq.Task) error {
|
|
var payload AccountPayload
|
|
|
|
if err := json.Unmarshal(t.Payload(), &payload); err != nil {
|
|
return fmt.Errorf("account: failed %v: %w", err, asynq.SkipRetry)
|
|
}
|
|
|
|
if err := cu.Noncestore.SetNewAccountNonce(ctx, payload.PublicKey); err != nil {
|
|
return err
|
|
}
|
|
|
|
_, err := cu.TaskerClient.CreateTask(
|
|
tasker.AccountRegisterTask,
|
|
tasker.DefaultPriority,
|
|
&tasker.Task{
|
|
Payload: t.Payload(),
|
|
},
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, err = cu.TaskerClient.CreateTask(
|
|
tasker.AccountGiftGasTask,
|
|
tasker.DefaultPriority,
|
|
&tasker.Task{
|
|
Payload: t.Payload(),
|
|
},
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, err = cu.TaskerClient.CreateTask(
|
|
tasker.AccountGiftVoucherTask,
|
|
tasker.DefaultPriority,
|
|
&tasker.Task{
|
|
Payload: t.Payload(),
|
|
},
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
eventPayload := events.EventPayload{
|
|
TrackingId: payload.TrackingId,
|
|
}
|
|
|
|
if err := cu.EventEmitter.Publish(
|
|
events.AccountNewNonce,
|
|
payload.PublicKey,
|
|
eventPayload,
|
|
); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|