MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / TopUpTask

Function TopUpTask

cmd/cql-proxy/api/database.go:390–491  ·  view source on GitHub ↗

TopUpTask handles the database balance/advance payments top-up process.

(ctx context.Context, cfg *config.Config, db *gorp.DbMap, t *model.Task)

Source from the content-addressed store, hash-verified

388
389// TopUpTask handles the database balance/advance payments top-up process.
390func TopUpTask(ctx context.Context, cfg *config.Config, db *gorp.DbMap, t *model.Task) (r gin.H, err error) {
391 args := struct {
392 Database proto.DatabaseID `json:"db"`
393 Amount uint64 `json:"amount"`
394 }{}
395
396 err = json.Unmarshal(t.RawArgs, &args)
397 if err != nil {
398 err = errors.Wrapf(err, "unmarshal task args failed")
399 return
400 }
401
402 dbAccount, err := args.Database.AccountAddress()
403 if err != nil {
404 err = errors.Wrapf(err, "get database wallet account failed")
405 return
406 }
407
408 p, err := model.GetAccountByID(db, t.Developer, t.Account)
409 if err != nil {
410 err = errors.Wrapf(err, "get account for task failed")
411 return
412 }
413
414 if err = p.LoadPrivateKey(); err != nil {
415 err = errors.Wrapf(err, "decode account private key failed")
416 return
417 }
418
419 accountAddr, err := p.Account.Get()
420 if err != nil {
421 err = errors.Wrapf(err, "decode task account failed")
422 return
423 }
424
425 // check for database account existence
426 var profile *types.SQLChainProfile
427 profile, err = getDatabaseProfile(args.Database)
428 if err != nil {
429 err = errors.Wrapf(err, "send get chain profile rpc failed")
430 return
431 }
432
433 foundUser := false
434 for _, user := range profile.Users {
435 if user.Address == accountAddr {
436 foundUser = true
437 break
438 }
439 }
440
441 if !foundUser {
442 err = errors.New("user does not have access to database")
443 return
444 }
445
446 nonceReq := new(types.NextAccountNonceReq)
447 nonceResp := new(types.NextAccountNonceResp)

Callers

nothing calls this directly

Calls 12

SignMethod · 0.95
GetAccountByIDFunction · 0.92
NewTransferFunction · 0.92
getDatabaseProfileFunction · 0.85
waitForTxStateFunction · 0.85
UnmarshalMethod · 0.80
AccountAddressMethod · 0.80
LoadPrivateKeyMethod · 0.80
GetMethod · 0.65
NewMethod · 0.65
HashMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected