-
Notifications
You must be signed in to change notification settings - Fork 95
Feature: Add support for unlimited assets. #900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
bd40522
Merge branch 'release/2.8.3'
onetechnical 4997285
Merge branch 'release/2.8.4'
bricerisingalgorand ae96643
Ledger refactoring changes (#870)
tolikzinovyev 76faddd
unlimited assets: backwards-compatible JSON encodings for account dat…
cce c941e78
REST API changes for unlimited assets (#872)
cce dadae50
Merge remote-tracking branch 'origin/develop' into feature/unlimited-…
cce 8444586
REST API: count include-all results when checking max resources limit…
cce 20c5ade
add "none" to exclude enum
cce ebc44d5
rename MaxAccountNestedObjects => MaxAPIResourcesPerAccount
cce b3ebf76
update docs for MaxAccountNestedObjects => MaxAPIResourcesPerAccount
cce 0a20fa2
remove "creator" from required since it has been removed from response
cce 12aaa71
achieve parity
cce 6bc3394
Merge branch 'release/2.9.0'
algobarb 6fdb088
Merge remote-tracking branch 'origin/master' into feature/unlimited-a…
cce ff54cba
Merge remote-tracking branch 'origin/develop' into feature/unlimited-…
cce 333fedf
add DisabledMapConfig to handles_e2e_test defaultOpts
cce 6402d35
Merge remote-tracking branch 'origin/develop' into feature/unlimited-…
cce 482097a
REST API: use ErrorResponse instead of AccountsErrorResponse (#916)
cce 2b82173
Merge branch 'develop' into feature/unlimited-assets
winder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,202 @@ | ||
| package accounting | ||
|
|
||
| import ( | ||
| "github.com/algorand/go-algorand/data/basics" | ||
| "github.com/algorand/go-algorand/data/transactions" | ||
| "github.com/algorand/go-algorand/ledger" | ||
| "github.com/algorand/go-algorand/protocol" | ||
| ) | ||
|
|
||
| // Add requests for asset and app creators to `assetsReq` and `appsReq` for the given | ||
| // transaction. | ||
| func addToCreatorsRequest(stxnad *transactions.SignedTxnWithAD, assetsReq map[basics.AssetIndex]struct{}, appsReq map[basics.AppIndex]struct{}) { | ||
| txn := &stxnad.Txn | ||
|
|
||
| switch txn.Type { | ||
| case protocol.AssetConfigTx: | ||
| fields := &txn.AssetConfigTxnFields | ||
| if fields.ConfigAsset != 0 { | ||
| assetsReq[fields.ConfigAsset] = struct{}{} | ||
| } | ||
| case protocol.AssetTransferTx: | ||
| fields := &txn.AssetTransferTxnFields | ||
| if fields.XferAsset != 0 { | ||
| assetsReq[fields.XferAsset] = struct{}{} | ||
| } | ||
| case protocol.AssetFreezeTx: | ||
| fields := &txn.AssetFreezeTxnFields | ||
| if fields.FreezeAsset != 0 { | ||
| assetsReq[fields.FreezeAsset] = struct{}{} | ||
| } | ||
| case protocol.ApplicationCallTx: | ||
| fields := &txn.ApplicationCallTxnFields | ||
| if fields.ApplicationID != 0 { | ||
| appsReq[fields.ApplicationID] = struct{}{} | ||
| } | ||
| for _, index := range fields.ForeignApps { | ||
| appsReq[index] = struct{}{} | ||
| } | ||
| for _, index := range fields.ForeignAssets { | ||
| assetsReq[index] = struct{}{} | ||
| } | ||
| } | ||
|
|
||
| for i := range stxnad.ApplyData.EvalDelta.InnerTxns { | ||
| addToCreatorsRequest(&stxnad.ApplyData.EvalDelta.InnerTxns[i], assetsReq, appsReq) | ||
| } | ||
| } | ||
|
|
||
| // MakePreloadCreatorsRequest makes a request for preloading creators in the batch mode. | ||
| func MakePreloadCreatorsRequest(payset transactions.Payset) (map[basics.AssetIndex]struct{}, map[basics.AppIndex]struct{}) { | ||
| assetsReq := make(map[basics.AssetIndex]struct{}, len(payset)) | ||
| appsReq := make(map[basics.AppIndex]struct{}, len(payset)) | ||
|
|
||
| for i := range payset { | ||
| addToCreatorsRequest(&payset[i].SignedTxnWithAD, assetsReq, appsReq) | ||
| } | ||
|
|
||
| return assetsReq, appsReq | ||
| } | ||
|
|
||
| // Add requests for account data and account resources to `addressesReq` and | ||
| // `resourcesReq` respectively for the given transaction. | ||
| func addToAccountsResourcesRequest(stxnad *transactions.SignedTxnWithAD, assetCreators map[basics.AssetIndex]ledger.FoundAddress, appCreators map[basics.AppIndex]ledger.FoundAddress, addressesReq map[basics.Address]struct{}, resourcesReq map[basics.Address]map[ledger.Creatable]struct{}) { | ||
| setResourcesReq := func(addr basics.Address, creatable ledger.Creatable) { | ||
| c, ok := resourcesReq[addr] | ||
| if !ok { | ||
| c = make(map[ledger.Creatable]struct{}) | ||
| resourcesReq[addr] = c | ||
| } | ||
| c[creatable] = struct{}{} | ||
| } | ||
|
|
||
| txn := &stxnad.Txn | ||
|
|
||
| addressesReq[txn.Sender] = struct{}{} | ||
|
|
||
| switch txn.Type { | ||
| case protocol.PaymentTx: | ||
| fields := &txn.PaymentTxnFields | ||
| addressesReq[fields.Receiver] = struct{}{} | ||
| // Close address is optional. | ||
| if !fields.CloseRemainderTo.IsZero() { | ||
| addressesReq[fields.CloseRemainderTo] = struct{}{} | ||
| } | ||
| case protocol.AssetConfigTx: | ||
| fields := &txn.AssetConfigTxnFields | ||
| if fields.ConfigAsset == 0 { | ||
| if stxnad.ApplyData.ConfigAsset != 0 { | ||
| creatable := ledger.Creatable{ | ||
| Index: basics.CreatableIndex(stxnad.ApplyData.ConfigAsset), | ||
| Type: basics.AssetCreatable, | ||
| } | ||
| setResourcesReq(txn.Sender, creatable) | ||
| } | ||
| } else { | ||
| if creator := assetCreators[fields.ConfigAsset]; creator.Exists { | ||
| creatable := ledger.Creatable{ | ||
| Index: basics.CreatableIndex(fields.ConfigAsset), | ||
| Type: basics.AssetCreatable, | ||
| } | ||
| addressesReq[creator.Address] = struct{}{} | ||
| setResourcesReq(creator.Address, creatable) | ||
| } | ||
| } | ||
| case protocol.AssetTransferTx: | ||
| fields := &txn.AssetTransferTxnFields | ||
| creatable := ledger.Creatable{ | ||
| Index: basics.CreatableIndex(fields.XferAsset), | ||
| Type: basics.AssetCreatable, | ||
| } | ||
| if creator := assetCreators[fields.XferAsset]; creator.Exists { | ||
| setResourcesReq(creator.Address, creatable) | ||
| } | ||
| source := txn.Sender | ||
| // If asset sender is non-zero, it is a clawback transaction. Otherwise, | ||
| // the transaction sender address is used. | ||
| if !fields.AssetSender.IsZero() { | ||
| source = fields.AssetSender | ||
| } | ||
| addressesReq[source] = struct{}{} | ||
| setResourcesReq(source, creatable) | ||
| addressesReq[fields.AssetReceiver] = struct{}{} | ||
| setResourcesReq(fields.AssetReceiver, creatable) | ||
| // Asset close address is optional. | ||
| if !fields.AssetCloseTo.IsZero() { | ||
| addressesReq[fields.AssetCloseTo] = struct{}{} | ||
| setResourcesReq(fields.AssetCloseTo, creatable) | ||
| } | ||
| case protocol.AssetFreezeTx: | ||
| fields := &txn.AssetFreezeTxnFields | ||
| creatable := ledger.Creatable{ | ||
| Index: basics.CreatableIndex(fields.FreezeAsset), | ||
| Type: basics.AssetCreatable, | ||
| } | ||
| if creator := assetCreators[fields.FreezeAsset]; creator.Exists { | ||
| setResourcesReq(creator.Address, creatable) | ||
| } | ||
| setResourcesReq(fields.FreezeAccount, creatable) | ||
| case protocol.ApplicationCallTx: | ||
| fields := &txn.ApplicationCallTxnFields | ||
| if fields.ApplicationID == 0 { | ||
| if stxnad.ApplyData.ApplicationID != 0 { | ||
| creatable := ledger.Creatable{ | ||
| Index: basics.CreatableIndex(stxnad.ApplyData.ApplicationID), | ||
| Type: basics.AppCreatable, | ||
| } | ||
| setResourcesReq(txn.Sender, creatable) | ||
| } | ||
| } else { | ||
| creatable := ledger.Creatable{ | ||
| Index: basics.CreatableIndex(fields.ApplicationID), | ||
| Type: basics.AppCreatable, | ||
| } | ||
| if creator := appCreators[fields.ApplicationID]; creator.Exists { | ||
| addressesReq[creator.Address] = struct{}{} | ||
| setResourcesReq(creator.Address, creatable) | ||
| } | ||
| setResourcesReq(txn.Sender, creatable) | ||
| } | ||
| for _, address := range fields.Accounts { | ||
| addressesReq[address] = struct{}{} | ||
| } | ||
| for _, index := range fields.ForeignApps { | ||
| if creator := appCreators[index]; creator.Exists { | ||
| creatable := ledger.Creatable{ | ||
| Index: basics.CreatableIndex(index), | ||
| Type: basics.AppCreatable, | ||
| } | ||
| setResourcesReq(creator.Address, creatable) | ||
| } | ||
| } | ||
| for _, index := range fields.ForeignAssets { | ||
| if creator := assetCreators[index]; creator.Exists { | ||
| creatable := ledger.Creatable{ | ||
| Index: basics.CreatableIndex(index), | ||
| Type: basics.AssetCreatable, | ||
| } | ||
| setResourcesReq(creator.Address, creatable) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| for i := range stxnad.ApplyData.EvalDelta.InnerTxns { | ||
| addToAccountsResourcesRequest( | ||
| &stxnad.ApplyData.EvalDelta.InnerTxns[i], assetCreators, appCreators, | ||
| addressesReq, resourcesReq) | ||
| } | ||
| } | ||
|
|
||
| // MakePreloadAccountsResourcesRequest makes a request for preloading account data and | ||
| // account resources in the batch mode. | ||
| func MakePreloadAccountsResourcesRequest(payset transactions.Payset, assetCreators map[basics.AssetIndex]ledger.FoundAddress, appCreators map[basics.AppIndex]ledger.FoundAddress) (map[basics.Address]struct{}, map[basics.Address]map[ledger.Creatable]struct{}) { | ||
| addressesReq := make(map[basics.Address]struct{}, len(payset)) | ||
| resourcesReq := make(map[basics.Address]map[ledger.Creatable]struct{}, len(payset)) | ||
|
|
||
| for i := range payset { | ||
| addToAccountsResourcesRequest( | ||
| &payset[i].SignedTxnWithAD, assetCreators, appCreators, addressesReq, resourcesReq) | ||
| } | ||
|
|
||
| return addressesReq, resourcesReq | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.