Skip to content

Commit

Permalink
Add asset close to amount field to transaction (algorand#1886)
Browse files Browse the repository at this point in the history
This PR adds `AssetClosingAmount` to the `ApplyData`, conditioned by a new `ConsensusParam.EnableAssetCloseAmount`. A corresponding `AssetClosingAmount` was added to the REST API to align with the variable already presents on the indexer v2.
  • Loading branch information
algorotem authored Feb 3, 2021
1 parent 731b6f4 commit cc49c51
Show file tree
Hide file tree
Showing 17 changed files with 638 additions and 377 deletions.
7 changes: 7 additions & 0 deletions config/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ type ConsensusParams struct {
// CompactCertSecKQ is the security parameter (k+q) for the compact
// certificate scheme.
CompactCertSecKQ uint64

// EnableAssetCloseAmount adds an extra field to the ApplyData. The field contains the amount of the remaining
// asset that were sent to the close-to address.
EnableAssetCloseAmount bool
}

// ConsensusProtocols defines a set of supported protocol versions and their
Expand Down Expand Up @@ -827,6 +831,9 @@ func initConsensusProtocols() {
vFuture.CompactCertWeightThreshold = (1 << 32) * 30 / 100
vFuture.CompactCertSecKQ = 128

// Enable AssetCloseAmount field
vFuture.EnableAssetCloseAmount = true

Consensus[protocol.ConsensusFuture] = vFuture
}

Expand Down
4 changes: 4 additions & 0 deletions daemon/algod/api/algod.oas2.json
Original file line number Diff line number Diff line change
Expand Up @@ -2148,6 +2148,10 @@
"description": "Closing amount for the transaction.",
"type": "integer"
},
"asset-closing-amount": {
"description": "The number of the asset's unit that were transferred to the close-to address.",
"type": "integer"
},
"confirmed-round": {
"description": "The round where this transaction was confirmed, if present.",
"type": "integer"
Expand Down
12 changes: 12 additions & 0 deletions daemon/algod/api/algod.oas3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,10 @@
"description": "The application index if the transaction was found and it created an application.",
"type": "integer"
},
"asset-closing-amount": {
"description": "The number of the asset's unit that were transferred to the close-to address.",
"type": "integer"
},
"asset-index": {
"description": "The asset index if the transaction was found and it created an asset.",
"type": "integer"
Expand Down Expand Up @@ -3129,6 +3133,10 @@
"description": "The application index if the transaction was found and it created an application.",
"type": "integer"
},
"asset-closing-amount": {
"description": "The number of the asset's unit that were transferred to the close-to address.",
"type": "integer"
},
"asset-index": {
"description": "The asset index if the transaction was found and it created an asset.",
"type": "integer"
Expand Down Expand Up @@ -3189,6 +3197,10 @@
"description": "The application index if the transaction was found and it created an application.",
"type": "integer"
},
"asset-closing-amount": {
"description": "The number of the asset's unit that were transferred to the close-to address.",
"type": "integer"
},
"asset-index": {
"description": "The asset index if the transaction was found and it created an asset.",
"type": "integer"
Expand Down
4 changes: 4 additions & 0 deletions daemon/algod/api/server/v1/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ func assetTransferTxEncode(tx transactions.Transaction, ad transactions.ApplyDat
xfer.CloseTo = tx.AssetTransferTxnFields.AssetCloseTo.String()
}

if ad.AssetClosingAmount != 0 {
xfer.CloseToAmount = ad.AssetClosingAmount
}

return v1.Transaction{
AssetTransfer: &xfer,
}
Expand Down
178 changes: 89 additions & 89 deletions daemon/algod/api/server/v2/generated/private/routes.go

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

3 changes: 3 additions & 0 deletions daemon/algod/api/server/v2/generated/private/types.go

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

Loading

0 comments on commit cc49c51

Please sign in to comment.