diff --git a/reference/Flow-PDS-API.yaml b/reference/Flow-PDS-API.yaml index 58702c5..526fbea 100644 --- a/reference/Flow-PDS-API.yaml +++ b/reference/Flow-PDS-API.yaml @@ -95,6 +95,7 @@ paths: name: distributionId in: path required: true + description: Distribution offchain ID get: summary: Get Distribution operationId: get-distribution-by-id @@ -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: diff --git a/service/app/contract_interface.go b/service/app/contract_interface.go index b87e7bb..5628ed6 100644 --- a/service/app/contract_interface.go +++ b/service/app/contract_interface.go @@ -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