Skip to content

Commit

Permalink
Incentives: Storing/ serving heartbeat transactions, synthetic transa…
Browse files Browse the repository at this point in the history
…ctions for payouts (#1635)

* Add support for storing and serving heartbeat transaction types

* Support generating synthetic payout transaction based off Payout being set in block header.

* Introduce transaction fetch API test case for heartbeats.
  • Loading branch information
gmalouf authored Dec 20, 2024
1 parent a99e6f7 commit c5c7b4e
Show file tree
Hide file tree
Showing 20 changed files with 1,041 additions and 458 deletions.
2 changes: 1 addition & 1 deletion api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The API is defined using [OpenAPI v2](https://swagger.io/specification/v2/) in *
The Makefile will install our fork of **oapi-codegen**, use `make oapi-codegen` to install it directly.

1. Document your changes by editing **indexer.oas2.yml**
2. Regenerate the endpoints by running **generate.sh**. The sources at **generated/** will be updated.
2. Regenerate the endpoints by running **make generate** from the `api` directory. The sources at **generated/** will be updated.
3. Update the implementation in **handlers.go**. It is sometimes useful to consult **generated/routes.go** to make sure the handler properly implements **ServerInterface**.

## What codegen tool is used?
Expand Down
26 changes: 22 additions & 4 deletions api/converter_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ func signedTxnWithAdToTransaction(stxn *sdk.SignedTxnWithAD, extra rowData) (gen
var assetTransfer *generated.TransactionAssetTransfer
var application *generated.TransactionApplication
var stateProof *generated.TransactionStateProof
var heartbeat *generated.TransactionHeartbeat

switch stxn.Txn.Type {
case sdk.PaymentTx:
Expand Down Expand Up @@ -585,6 +586,22 @@ func signedTxnWithAdToTransaction(stxn *sdk.SignedTxnWithAD, extra rowData) (gen
StateProofType: uint64Ptr(uint64(stxn.Txn.StateProofType)),
}
stateProof = &proofTxn
case sdk.HeartbeatTx:
hb := stxn.Txn.HeartbeatTxnFields
hbTxn := generated.TransactionHeartbeat{
HbAddress: hb.HbAddress.String(),
HbKeyDilution: hb.HbKeyDilution,
HbProof: generated.HbProofFields{
HbPk: byteSliceOmitZeroPtr(hb.HbProof.PK[:]),
HbPk1sig: byteSliceOmitZeroPtr(hb.HbProof.PK1Sig[:]),
HbPk2: byteSliceOmitZeroPtr(hb.HbProof.PK2[:]),
HbPk2sig: byteSliceOmitZeroPtr(hb.HbProof.PK2Sig[:]),
HbSig: byteSliceOmitZeroPtr(hb.HbProof.Sig[:]),
},
HbSeed: hb.HbSeed[:],
HbVoteId: hb.HbVoteID[:],
}
heartbeat = &hbTxn
}

var localStateDelta *[]generated.AccountStateDelta
Expand Down Expand Up @@ -635,9 +652,9 @@ func signedTxnWithAdToTransaction(stxn *sdk.SignedTxnWithAD, extra rowData) (gen
for _, t := range stxn.ApplyData.EvalDelta.InnerTxns {
extra2 := extra
if t.Txn.Type == sdk.ApplicationCallTx {
extra2.AssetID = uint64(t.ApplyData.ApplicationID)
extra2.AssetID = t.ApplyData.ApplicationID
} else if t.Txn.Type == sdk.AssetConfigTx {
extra2.AssetID = uint64(t.ApplyData.ConfigAsset)
extra2.AssetID = t.ApplyData.ConfigAsset
} else {
extra2.AssetID = 0
}
Expand All @@ -661,6 +678,7 @@ func signedTxnWithAdToTransaction(stxn *sdk.SignedTxnWithAD, extra rowData) (gen
PaymentTransaction: payment,
KeyregTransaction: keyreg,
StateProofTransaction: stateProof,
HeartbeatTransaction: heartbeat,
ClosingAmount: uint64Ptr(uint64(stxn.ClosingAmount)),
ConfirmedRound: uint64Ptr(extra.Round),
IntraRoundOffset: uint64Ptr(uint64(extra.Intra)),
Expand Down Expand Up @@ -951,9 +969,9 @@ func (si *ServerImplementation) blockParamsToBlockFilter(params generated.Search

func (si *ServerImplementation) maxAccountsErrorToAccountsErrorResponse(maxErr idb.MaxAPIResourcesPerAccountError) generated.ErrorResponse {
addr := maxErr.Address.String()
max := uint64(si.opts.MaxAPIResourcesPerAccount)
maxResults := si.opts.MaxAPIResourcesPerAccount
extraData := map[string]interface{}{
"max-results": max,
"max-results": maxResults,
"address": addr,
"total-assets-opted-in": maxErr.TotalAssets,
"total-created-assets": maxErr.TotalAssetParams,
Expand Down
18 changes: 0 additions & 18 deletions api/generate.sh

This file was deleted.

377 changes: 192 additions & 185 deletions api/generated/common/routes.go

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions api/generated/common/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c5c7b4e

Please sign in to comment.