Skip to content

Commit c5c7b4e

Browse files
authored
Incentives: Storing/ serving heartbeat transactions, synthetic transactions 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.
1 parent a99e6f7 commit c5c7b4e

File tree

20 files changed

+1041
-458
lines changed

20 files changed

+1041
-458
lines changed

api/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The API is defined using [OpenAPI v2](https://swagger.io/specification/v2/) in *
99
The Makefile will install our fork of **oapi-codegen**, use `make oapi-codegen` to install it directly.
1010

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

1515
## What codegen tool is used?

api/converter_utils.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ func signedTxnWithAdToTransaction(stxn *sdk.SignedTxnWithAD, extra rowData) (gen
382382
var assetTransfer *generated.TransactionAssetTransfer
383383
var application *generated.TransactionApplication
384384
var stateProof *generated.TransactionStateProof
385+
var heartbeat *generated.TransactionHeartbeat
385386

386387
switch stxn.Txn.Type {
387388
case sdk.PaymentTx:
@@ -585,6 +586,22 @@ func signedTxnWithAdToTransaction(stxn *sdk.SignedTxnWithAD, extra rowData) (gen
585586
StateProofType: uint64Ptr(uint64(stxn.Txn.StateProofType)),
586587
}
587588
stateProof = &proofTxn
589+
case sdk.HeartbeatTx:
590+
hb := stxn.Txn.HeartbeatTxnFields
591+
hbTxn := generated.TransactionHeartbeat{
592+
HbAddress: hb.HbAddress.String(),
593+
HbKeyDilution: hb.HbKeyDilution,
594+
HbProof: generated.HbProofFields{
595+
HbPk: byteSliceOmitZeroPtr(hb.HbProof.PK[:]),
596+
HbPk1sig: byteSliceOmitZeroPtr(hb.HbProof.PK1Sig[:]),
597+
HbPk2: byteSliceOmitZeroPtr(hb.HbProof.PK2[:]),
598+
HbPk2sig: byteSliceOmitZeroPtr(hb.HbProof.PK2Sig[:]),
599+
HbSig: byteSliceOmitZeroPtr(hb.HbProof.Sig[:]),
600+
},
601+
HbSeed: hb.HbSeed[:],
602+
HbVoteId: hb.HbVoteID[:],
603+
}
604+
heartbeat = &hbTxn
588605
}
589606

590607
var localStateDelta *[]generated.AccountStateDelta
@@ -635,9 +652,9 @@ func signedTxnWithAdToTransaction(stxn *sdk.SignedTxnWithAD, extra rowData) (gen
635652
for _, t := range stxn.ApplyData.EvalDelta.InnerTxns {
636653
extra2 := extra
637654
if t.Txn.Type == sdk.ApplicationCallTx {
638-
extra2.AssetID = uint64(t.ApplyData.ApplicationID)
655+
extra2.AssetID = t.ApplyData.ApplicationID
639656
} else if t.Txn.Type == sdk.AssetConfigTx {
640-
extra2.AssetID = uint64(t.ApplyData.ConfigAsset)
657+
extra2.AssetID = t.ApplyData.ConfigAsset
641658
} else {
642659
extra2.AssetID = 0
643660
}
@@ -661,6 +678,7 @@ func signedTxnWithAdToTransaction(stxn *sdk.SignedTxnWithAD, extra rowData) (gen
661678
PaymentTransaction: payment,
662679
KeyregTransaction: keyreg,
663680
StateProofTransaction: stateProof,
681+
HeartbeatTransaction: heartbeat,
664682
ClosingAmount: uint64Ptr(uint64(stxn.ClosingAmount)),
665683
ConfirmedRound: uint64Ptr(extra.Round),
666684
IntraRoundOffset: uint64Ptr(uint64(extra.Intra)),
@@ -951,9 +969,9 @@ func (si *ServerImplementation) blockParamsToBlockFilter(params generated.Search
951969

952970
func (si *ServerImplementation) maxAccountsErrorToAccountsErrorResponse(maxErr idb.MaxAPIResourcesPerAccountError) generated.ErrorResponse {
953971
addr := maxErr.Address.String()
954-
max := uint64(si.opts.MaxAPIResourcesPerAccount)
972+
maxResults := si.opts.MaxAPIResourcesPerAccount
955973
extraData := map[string]interface{}{
956-
"max-results": max,
974+
"max-results": maxResults,
957975
"address": addr,
958976
"total-assets-opted-in": maxErr.TotalAssets,
959977
"total-created-assets": maxErr.TotalAssetParams,

api/generate.sh

Lines changed: 0 additions & 18 deletions
This file was deleted.

api/generated/common/routes.go

Lines changed: 192 additions & 185 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/generated/common/types.go

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)