Skip to content

ABI-compliant app routing #167

@jasonpaulos

Description

@jasonpaulos

Summary

Provide a way for an application to handle requests in compliance with https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0004.md#implementing-a-method

Scope

This might look like an ABIRouter object that you can use to build up the different routes. For example:

router = ABIRouter()

router.onBareAppCall(OnComplete.NoOp, handleCreate, creation=True)
router.onBareAppCall(OnComplete.OptIn, handleOptIn)
router.onBareAppCall([OnComplete.CloseOut, OnComplete.ClearState], handleCloseOut)
router.onBareAppCall([OnComplete.Update, OnComplete.Delete], handleUpdateOrDelete)

router.onMethodCall("add(uint64,uint64)uint128", handleAdd)
router.onMethodCall("multiply(uint64,uint64)uint128", handleMultiply)
router.onMethodCall("optInAndAdd(uint64,uint64)uint128", handleOptInAndAdd, OnComplete.OptIn)
router.onMethodCall("createWithAMethod()string", handleCreateWithAMethod, creation=True)

approvalAST, clearStateAST = router.buildPrograms()

onBareAppCall can be used to register a bare app call (defined in the ABI as a call with no arguments or return value). The allowed on completion actions must be specified, as well as whether the bare call can be invoked during creation or not.

onMethodCall can be used to register a method call. By default OnComplete.NoOp will be the only allowed on completion action, but others may be specified. Additionally, you can pass in a value for creation if this method call should be invoked during app creation or not.

Ideally the router would also unpack the arguments and pass them to the handler function, as well as take any return value from the handler function and prefix and log it appropriately. Though this might require some more thought to implement properly.

buildPrograms would construct ASTs for both the approval and clear programs based on the inputs to the router. If any routes can be accessed with OnComplete.ClearState, these routes will be added to the clear state program.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions