mirror of
https://github.com/grassrootseconomics/cic-custodial.git
synced 2025-02-18 00:34:12 +01:00
Squashed commit of the following: commit05e1396121
Author: Mohammed Sohail <sohailsameja@gmail.com> Date: Wed Feb 15 10:03:44 2023 +0300 feat: add status types to dispatcher commit397cd78ca9
Author: Mohammed Sohail <sohailsameja@gmail.com> Date: Wed Feb 15 09:39:31 2023 +0300 deps: bump -> cic-celo-sdk commitf2ba079232
Author: Mohammed Sohail <sohailsameja@gmail.com> Date: Sun Feb 12 16:53:53 2023 +0300 snapshot: 12-ebening commit4f7909e4ee
Author: Mohammed Sohail <sohailsameja@gmail.com> Date: Sun Feb 12 12:50:43 2023 +0300 xnapshot: 12-02 commit773474cad9
Author: Mohammed Sohail <sohailsameja@gmail.com> Date: Thu Feb 9 14:23:37 2023 +0300 update: deps initializers commit8a0880fcfc
Author: Mohammed Sohail <sohailsameja@gmail.com> Date: Thu Feb 9 10:42:15 2023 +0300 wip: refactor taskers commit8676450122
Author: Mohammed Sohail <sohailsameja@gmail.com> Date: Fri Feb 3 12:29:27 2023 +0300 refactor: decouple sql queries, remove transfer * add inline docs * removed transfer taks in prep for re-write commitb4c09cd11a
Author: Mohammed Sohail <sohailsameja@gmail.com> Date: Thu Feb 2 12:29:43 2023 +0000 refactor: cmd/service/* and api
65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/grassrootseconomics/cic-custodial/internal/keystore"
|
|
"github.com/grassrootseconomics/cic-custodial/internal/tasker"
|
|
"github.com/grassrootseconomics/cic-custodial/internal/tasker/task"
|
|
"github.com/grassrootseconomics/cic-custodial/pkg/keypair"
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
// CreateAccountHandler route.
|
|
// POST: /api/account/create
|
|
// Returns the public key.
|
|
func CreateAccountHandler(
|
|
keystore keystore.Keystore,
|
|
taskerClient *tasker.TaskerClient,
|
|
) func(echo.Context) error {
|
|
return func(c echo.Context) error {
|
|
trackingId := uuid.NewString()
|
|
|
|
generatedKeyPair, err := keypair.Generate()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
id, err := keystore.WriteKeyPair(c.Request().Context(), generatedKeyPair)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
taskPayload, err := json.Marshal(task.AccountPayload{
|
|
PublicKey: generatedKeyPair.Public,
|
|
TrackingId: trackingId,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, err = taskerClient.CreateTask(
|
|
tasker.PrepareAccountTask,
|
|
tasker.DefaultPriority,
|
|
&tasker.Task{
|
|
Id: trackingId,
|
|
Payload: taskPayload,
|
|
},
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return c.JSON(http.StatusOK, OkResp{
|
|
Ok: true,
|
|
Result: H{
|
|
"publicKey": generatedKeyPair.Public,
|
|
"custodialId": id,
|
|
"trackingId": trackingId,
|
|
},
|
|
})
|
|
}
|
|
}
|