Skip to content

Commit

Permalink
Allow manually aborting a distribution via API
Browse files Browse the repository at this point in the history
  • Loading branch information
latenssi committed Oct 7, 2021
1 parent cbc346d commit b75884e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
6 changes: 3 additions & 3 deletions reference/Flow-PDS-API.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ paths:
name: distributionId
in: path
required: true
description: Distribution offchain ID
get:
summary: Get Distribution
operationId: get-distribution-by-id
Expand All @@ -113,16 +114,15 @@ paths:
name: distributionId
in: path
required: true
description: Distribution offchain ID
post:
summary: Abort distribution
operationId: abort-distribution
responses:
'200':
description: OK
description: |-
THIS ENDOINT IS NOT IMPLEMENTED
description: Forcibly abort the process, which will put the Distribution into the Invalid state.

Forcibly abort the process, which will put the Distribution into the Invalid state.
components:
schemas: {}
responses:
Expand Down
3 changes: 1 addition & 2 deletions service/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ func (app *App) GetDistribution(ctx context.Context, id uuid.UUID) (*Distributio
return distribution, nil
}

// AbortDistribution aborts a distribution. Spec and implementation for
// distribution aborting is not finished yet.
// AbortDistribution aborts a distribution.
func (app *App) AbortDistribution(ctx context.Context, id uuid.UUID) error {
return app.db.Transaction(func(tx *gorm.DB) error {
distribution, err := GetDistribution(tx, id)
Expand Down
37 changes: 28 additions & 9 deletions service/app/contract_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,24 +316,43 @@ func (c *Contract) StartMinting(ctx context.Context, db *gorm.DB, dist *Distribu

// Abort a distribution
func (c *Contract) Abort(ctx context.Context, db *gorm.DB, dist *Distribution) error {
// TODO (latenssi)

c.logger.WithFields(log.Fields{
"method": "Abort",
"ID": dist.ID,
}).Info("Abort")

return fmt.Errorf("abort is not yet implemented")
if err := dist.SetInvalid(); err != nil {
return err
}

// if err := dist.SetAborted(); err != nil {
// return err
// }
if err := UpdateDistribution(db, dist); err != nil {
return err
}

// if err := UpdateDistribution(db, dist); err != nil {
// return err
// }
// Update distribution state onchain
txScript := util.ParseCadenceTemplate(UPDATE_STATE_SCRIPT)
arguments := []cadence.Value{
cadence.UInt64(dist.FlowID.Int64),
cadence.UInt8(1),
}
t, err := transactions.NewTransaction(UPDATE_STATE_SCRIPT, txScript, arguments)
if err != nil {
return err
}

if err := t.Save(db); err != nil {
return err
}

// return nil
c.logger.WithFields(log.Fields{
"method": "Abort",
"ID": dist.ID,
"state": 1,
"stateStr": "invalid",
}).Info("Distribution state update transaction saved")

return nil
}

// UpdateSettlementStatus polls for 'Deposit' events regarding the given distributions
Expand Down

0 comments on commit b75884e

Please sign in to comment.