Skip to content

Commit

Permalink
Merge pull request #1007 from stechu/teal-compile-api
Browse files Browse the repository at this point in the history
New v2 API endpoint for compile teal code:
/v2/compile
POST text/plain utf-8 encoded source code
Return json if succeed
{
“result”:base64 encoded bytes,
“hash”:base32 sha512_256 of program bytes (Address style),
}
Otherwise 400 error (bad request) with actual error message
  • Loading branch information
brianolson committed May 27, 2020
2 parents 6099194 + f7d7ea2 commit 287fb3a
Show file tree
Hide file tree
Showing 9 changed files with 458 additions and 217 deletions.
75 changes: 74 additions & 1 deletion daemon/algod/api/algod.oas2.json
Expand Up @@ -668,7 +668,60 @@
"required": true
}
]
}
},
"/v2/teal/compile": {
"post": {
"description": "Given TEAL source code in plain text, return base64 encoded program bytes and base32 SHA512_256 hash of program bytes (Address style).",
"consumes": [
"text/plain"
],
"produces": [
"application/json"
],
"schemes": [
"http"
],
"summary": "Compile TEAL source code to binary, produce its hash",
"operationId": "TealCompile",
"parameters": [
{
"description": "TEAL source code to be compiled",
"name": "source",
"in": "body",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"$ref": "#/responses/PostCompileResponse"
},
"400": {
"description": "Bad Request - Teal Compile Error",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
},
"401": {
"description": "Invalid API Token",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
},
"500": {
"description": "Internal Error",
"schema": {
"$ref": "#/definitions/ErrorResponse"
}
},
"default": {
"description": "Unknown Error"
}
}
}
}
},
"definitions": {
"Account": {
Expand Down Expand Up @@ -1359,6 +1412,26 @@
},
"x-go-package": "github.com/algorand/go-algorand/daemon/algod/api/spec/v1"
}
},
"PostCompileResponse": {
"description": "Teal compile Result",
"schema": {
"type": "object",
"required": [
"hash",
"result"
],
"properties": {
"hash": {
"description": "base32 SHA512_256 of program bytes (Address style)",
"type": "string"
},
"result":{
"description": "base64 encoded program bytes",
"type": "string"
}
}
}
}
},
"securityDefinitions": {
Expand Down
103 changes: 103 additions & 0 deletions daemon/algod/api/algod.oas3.yml
Expand Up @@ -382,6 +382,30 @@
},
"description": "A potentially truncated list of transactions currently in the node's transaction pool. You can compute whether or not the list is truncated if the number of elements in the **top-transactions** array is fewer than **total-transactions**."
},
"PostCompileResponse": {
"content": {
"application/json": {
"schema": {
"properties": {
"hash": {
"description": "base32 SHA512_256 of program bytes (Address style)",
"type": "string"
},
"result": {
"description": "base64 encoded program bytes",
"type": "string"
}
},
"required": [
"hash",
"result"
],
"type": "object"
}
}
},
"description": "Teal compile Result"
},
"PostTransactionsResponse": {
"content": {
"application/json": {
Expand Down Expand Up @@ -1536,6 +1560,85 @@
"summary": "Gets the node status after waiting for the given round."
}
},
"/v2/teal/compile": {
"post": {
"description": "Given TEAL source code in plain text, return base64 encoded program bytes and base32 SHA512_256 hash of program bytes (Address style).",
"operationId": "TealCompile",
"requestBody": {
"content": {
"text/plain": {
"schema": {
"type": "string"
}
}
},
"description": "TEAL source code to be compiled",
"required": true
},
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"properties": {
"hash": {
"description": "base32 SHA512_256 of program bytes (Address style)",
"type": "string"
},
"result": {
"description": "base64 encoded program bytes",
"type": "string"
}
},
"required": [
"hash",
"result"
],
"type": "object"
}
}
},
"description": "Teal compile Result"
},
"400": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
},
"description": "Bad Request - Teal Compile Error"
},
"401": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
},
"description": "Invalid API Token"
},
"500": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ErrorResponse"
}
}
},
"description": "Internal Error"
},
"default": {
"content": {},
"description": "Unknown Error"
}
},
"summary": "Compile TEAL source code to binary, produce its hash",
"x-codegen-request-body-name": "source"
}
},
"/v2/transactions": {
"post": {
"operationId": "RawTransaction",
Expand Down

0 comments on commit 287fb3a

Please sign in to comment.