-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 143a905
Showing
52 changed files
with
3,273 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,9 @@ | ||
* text=auto | ||
|
||
*.lua eol=lf | ||
*.ligo eol=lf | ||
*.mligo eol=lf | ||
*.jsligo eol=lf | ||
*.religo eol=lf | ||
*.hjson eol=lf | ||
*.json eol=lf |
This file contains 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,18 @@ | ||
# ami & eli definitions | ||
__tea/.ami-definitions/eli/* | ||
!__tea/.ami-definitions/eli/.gitkeep | ||
__tea/.ami-definitions/ami/* | ||
!__tea/.ami-definitions/ami/.gitkeep | ||
__tea/bin/* | ||
!__tea/bin/.gitkeep | ||
|
||
# ligo | ||
**/.ligo-work | ||
|
||
# build | ||
build/* | ||
!build/.gitkeep | ||
|
||
# deploy | ||
deploy/* | ||
!deploy/.gitkeep |
This file contains 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,88 @@ | ||
{ | ||
"Lua.runtime.version": "Lua 5.4", | ||
"Lua.misc.parameters": [ "--preview" ], | ||
"Lua.workspace.library": [ | ||
"./__tea/.ami-definitions/eli", | ||
"./__tea/.ami-definitions/ami" | ||
], | ||
"Lua.diagnostics.globals": [ | ||
"cli", | ||
"env", | ||
"fs", | ||
"hash", | ||
"Logger", | ||
"lz", | ||
"net", | ||
"path", | ||
"proc", | ||
"tar", | ||
"util", | ||
"ver", | ||
"zip", | ||
|
||
"am", | ||
"hjson", | ||
|
||
"log_success", | ||
"log_trace", | ||
"log_debug", | ||
"log_info", | ||
"log_warn", | ||
"log_error", | ||
"ami_error", | ||
"ami_assert", | ||
|
||
"PLUGIN_IN_MEM_CACHE", | ||
"GLOBAL_LOGGER", | ||
|
||
"EXIT_SETUP_ERROR", | ||
"EXIT_NOT_INSTALLED", | ||
"EXIT_NOT_IMPLEMENTED", | ||
"EXIT_MISSING_API", | ||
"EXIT_ELEVATION_REQUIRED", | ||
"EXIT_SETUP_REQUIRED", | ||
"EXIT_UNSUPPORTED_PLATFORM", | ||
"EXIT_MISSING_PERMISSION", | ||
"EXIT_INVALID_ELI_VERSION", | ||
"EXIT_AMI_UPDATE_REQUIRED", | ||
"EXIT_INVALID_CONFIGURATION", | ||
"EXIT_INVALID_AMI_VERSION", | ||
"EXIT_INVALID_AMI_BASE_INTERFACE", | ||
"EXIT_APP_INVALID_MODEL", | ||
"EXIT_APP_DOWNLOAD_ERROR", | ||
"EXIT_APP_IO_ERROR", | ||
"EXIT_APP_UN_ERROR", | ||
"EXIT_APP_CONFIGURE_ERROR", | ||
"EXIT_APP_START_ERROR", | ||
"EXIT_APP_STOP_ERROR", | ||
"EXIT_APP_INFO_ERROR", | ||
"EXIT_APP_ABOUT_ERROR", | ||
"EXIT_APP_INTERNAL_ERROR", | ||
"EXIT_APP_UPDATE_ERROR", | ||
"EXIT_CLI_SCHEME_MISSING", | ||
"EXIT_CLI_ACTION_MISSING", | ||
"EXIT_CLI_ARG_VALIDATION_ERROR", | ||
"EXIT_CLI_INVALID_VALUE", | ||
"EXIT_CLI_INVALID_DEFINITION", | ||
"EXIT_CLI_CMD_UNKNOWN", | ||
"EXIT_CLI_OPTION_UNKNOWN", | ||
"EXIT_RM_ERROR", | ||
"EXIT_RM_DATA_ERROR", | ||
"EXIT_TPL_READ_ERROR", | ||
"EXIT_TPL_WRITE_ERROR", | ||
"EXIT_PLUGIN_DOWNLOAD_ERROR", | ||
"EXIT_PLUGIN_INVALID_DEFINITION", | ||
"EXIT_PLUGIN_LOAD_ERROR", | ||
"EXIT_PLUGIN_EXEC_ERROR", | ||
"EXIT_PKG_DOWNLOAD_ERROR", | ||
"EXIT_PKG_INVALID_DEFINITION", | ||
"EXIT_PKG_INVALID_VERSION", | ||
"EXIT_PKG_INVALID_TYPE", | ||
"EXIT_PKG_INTEGRITY_CHECK_ERROR", | ||
"EXIT_PKG_LOAD_ERROR", | ||
"EXIT_PKG_LAYER_EXTRACT_ERROR", | ||
"EXIT_PKG_MODEL_GENERATION_ERROR", | ||
"EXIT_INVALID_SOURCES_FILE", | ||
"EXIT_UNKNOWN_ERROR" | ||
] | ||
} |
This file contains 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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 alis.is | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Empty file.
This file contains 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,15 @@ | ||
local _metaStore = "__tea/.ami-definitions/" | ||
local _eliMetaZip = _metaStore .. "eli/meta.zip" | ||
local _amiMetaZip = _metaStore .. "ami/meta.zip" | ||
|
||
log_info("Downloading metas...") | ||
net.download_file("https://github.com/alis-is/eli/releases/latest/download/meta.zip", _eliMetaZip, | ||
{ followRedirects = true }) | ||
net.download_file("https://github.com/alis-is/ami/releases/latest/download/meta.zip", _amiMetaZip, | ||
{ followRedirects = true }) | ||
|
||
log_info("Extracting metas...") | ||
zip.extract(_eliMetaZip, _metaStore .. "eli", { flattenRootDir = true }) | ||
zip.extract(_amiMetaZip, _metaStore .. "ami", { flattenRootDir = true }) | ||
|
||
log_success("eli & ami definitions downloaded") |
Empty file.
This file contains 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,46 @@ | ||
local _computed = require "__tea.common.computed" | ||
|
||
if type(_computed.CONTAINER_ENGINE) ~= "string" then | ||
log_warn("Failed to detect container engine! You need one to be able to run sandbox.") | ||
log_info("HINT: For docker see https://docs.docker.com/compose/gettingstarted/") | ||
log_info("HINT: For podman see https://podman.io/getting-started/installation") | ||
else | ||
log_info(_computed.CONTAINER_ENGINE .. " detected.") | ||
end | ||
|
||
if _computed.USE_LIGO_CONTAINER then | ||
log_info("'image' in ligo configuration detected. Static ligo binary won't be downloaded.") | ||
else | ||
-- download ligo | ||
local _ligoVersion = am.app.get_configuration({ "ligo", "version" }, "latest") | ||
log_info("Searching " .. _ligoVersion .. " ligo binary...") | ||
-- 12294987 ligo project ID | ||
local _releasesUrl = "https://gitlab.com/api/v4/projects/12294987/releases/" .. | ||
(_ligoVersion == "latest" and "" or _ligoVersion) | ||
local _releaseInfo = net.download_string(_releasesUrl) | ||
if not _releaseInfo then return ami_error("Failed to obtain ligo release info from gitlab.") end | ||
local _releases = hjson.parse(_releaseInfo) | ||
local _latest | ||
if _ligoVersion == "latest" then | ||
_latest = _releases[1] -- lua indexes from 1 ;) | ||
else | ||
_latest = _releases | ||
end | ||
|
||
local _links = _latest.assets.links | ||
local _pattern = ("Static Linux binary"):gsub('(%a)', function(v) return '[' .. v:lower() .. v:upper() .. ']' end) | ||
local _ligoUrl | ||
for _, link in ipairs(_links) do | ||
if link.name:match(_pattern) then | ||
_ligoUrl = link.url | ||
break | ||
end | ||
end | ||
ami_assert(_ligoUrl, | ||
"Failed to get static linux binary URL!\nPlease try to specify LIGO_VERSION in configuration section of your app.hjson.") | ||
local _ligoDestination = "__tea/bin/ligo" | ||
log_info("Downloading " .. _latest.tag_name .. " ligo binary...") | ||
net.download_file(_ligoUrl, "__tea/bin/ligo", { showDefaultProgress = 10 }) | ||
fs.chmod(_ligoDestination, 755) | ||
log_success("ligo binary downloaded") | ||
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
This file contains 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,84 @@ | ||
-- containers | ||
local function _get_container_engine() | ||
local _prefers = am.app.get_configuration({ "containers", "engine" }) | ||
if type(_prefers) == "string" then return _prefers end | ||
-- we prefer rootless setups so podman by default | ||
if os.execute "podman --version > /dev/null" then | ||
return "podman" | ||
end | ||
if os.execute "docker --version > /dev/null" then | ||
return "docker" | ||
end | ||
return nil | ||
end | ||
|
||
local _containerEngine = _get_container_engine() | ||
|
||
-- ligo | ||
local _ligoContainer = type(am.app.get_configuration({ "ligo", "image" })) == "string" | ||
local _protocol = am.app.get_configuration({ "ligo", "protocol" }) | ||
local _syntax = am.app.get_configuration({ "ligo", "syntax" }, "cameligo") | ||
local function _get_ligo_cmd() | ||
if _ligoContainer then | ||
return string.interpolate('${ENGINE} run --rm -v "$PWD":"$PWD" -w "$PWD" ${IMAGE}', { | ||
ENGINE = _containerEngine, | ||
IMAGE = _ligoContainer | ||
}) | ||
end | ||
return "./__tea/bin/ligo" | ||
end | ||
|
||
local function _find_file(dir, name) | ||
local _candidates = fs.read_dir(dir, { returnFullPaths = true, asDirEntries = true }) | ||
for _, candidate in ipairs(_candidates) do | ||
if string.match(candidate:name(), "^" .. name) then | ||
return candidate:fullpath() | ||
end | ||
end | ||
return "src/contract.mligo" | ||
end | ||
|
||
local _deploys = am.app.get_configuration("deploys", {}) | ||
for _, v in pairs(_deploys) do | ||
v.INITIAL_STORAGE_ARGS = am.app.get_configuration({ "ligo", "initial-storage-args" }, | ||
"(${admin-addr}: address), ${metadata}") | ||
end | ||
|
||
return { | ||
ID = am.app.get("id", "tea-contract"), | ||
USE_LIGO_CONTAINER = _ligoContainer, | ||
CONTAINER_ENGINE = _containerEngine, | ||
SANDBOX_VARS = { | ||
ENGINE = _containerEngine, | ||
NAME = am.app.get_configuration({ "sandbox", "name" }, "snadbox-" .. am.app.get("id", "tezos")), | ||
IMAGE = am.app.get_configuration({ "sandbox", "image" }, "oxheadalpha/flextesa:latest"), | ||
SCRIPT = am.app.get_configuration({ "sandbox", "script" }, "kathmandubox"), | ||
RPC_PORT = am.app.get_configuration({ "sandbox", "rpc_port" }, "20000") | ||
}, | ||
LIGO_VARS = { | ||
LIGO = _get_ligo_cmd(), | ||
CONTRACT_ID = am.app.get("id", "tea-contract"), | ||
FILE = am.app.get_configuration({ "ligo", "contract-file" }, _find_file("src", "contract")), | ||
ENTRYPOINT = am.app.get_configuration({ "ligo", "contract-entrypoint" }, "main"), | ||
PROTOCOL = _protocol, | ||
PROTOCOL_ARG = _protocol and "--protocol " .. _protocol or "", | ||
SYNTAX = _syntax, | ||
SYNTAX_ARG = "--syntax " .. _syntax, | ||
BUILD_DIR = am.app.get_configuration({ "ligo", "build-directory" }, "build"), | ||
}, | ||
DEPLOYS = _deploys, | ||
COMPILE = { | ||
TZ = am.app.get_configuration({ "compile", "tz" }, true), | ||
JSON = am.app.get_configuration({ "compile", "json" }, true), | ||
}, | ||
TEST_VARS = { | ||
ROOT = am.app.get_configuration({ "tests", "root" }, _find_file("tests", "all")) | ||
}, | ||
METADATA_VARS = { | ||
SOURCE = am.app.get_configuration({ "metadata", "source" }, "src/metadata.hjson"), | ||
OFFCHAIN_VIEWS = am.app.get_configuration({ "metadata", "offchain-views" }, "src/offchain-views.hjson"), | ||
INDENT = am.app.get_configuration({ "metadata", "indent" }, false), | ||
OFFCHAIN_VIEW_EXP_SUFFIX = am.app.get_configuration({ "metadata", "offchain-view-expression-suffix" }, | ||
"_off_chain_view") | ||
} | ||
} |
This file contains 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,19 @@ | ||
log_success, log_info = util.global_log_factory("eli", "success", "info") | ||
|
||
local _configuration = require"hjson".parse(fs.read_file("src/config.hjson")) | ||
for k, v in pairs(_configuration) do | ||
_G[k] = v | ||
end | ||
|
||
local _offChainViews = require"hjson".parse(fs.read_file("src/offchain-views.hjson")) | ||
local _contractMetadata = require"hjson".parse(fs.read_file("src/metadata.hjson")) | ||
|
||
_G.configuration = _configuration | ||
_G.CONTRACT_METADATA = _contractMetadata | ||
_G.OFFCHAIN_VIEWS = _offChainViews | ||
|
||
return { | ||
configuration = _configuration, | ||
offchainViews = _offChainViews, | ||
contractMetadata = _contractMetadata | ||
} |
This file contains 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,22 @@ | ||
local _computed = require "__tea.common.computed" | ||
|
||
local _cmd = _computed.LIGO_VARS.LIGO .. " compile contract ${FILE} --entry-point ${ENTRYPOINT}" .. | ||
" --michelson-format ${FORMAT} --output-file ${BUILD_DIR}/${CONTRACT_ID}${SUFFIX} ${PROTOCOL_ARG} ${SYNTAX_ARG}" | ||
|
||
if _computed.COMPILE.TZ then | ||
log_info("Compiling contract to ${ID}.tz...", _computed) | ||
local _ok = os.execute(string.interpolate(_cmd, util.merge_tables(_computed.LIGO_VARS, { | ||
FORMAT = "text", | ||
SUFFIX = ".tz" | ||
}))) | ||
ami_assert(_ok, string.interpolate("Failed to compile contract ${ID}.tz", _computed)) | ||
end | ||
|
||
if _computed.COMPILE.JSON then | ||
log_info("Compiling contract to ${ID}.json...", _computed) | ||
local _ok = os.execute(string.interpolate(_cmd, util.merge_tables(_computed.LIGO_VARS, { | ||
FORMAT = "json", | ||
SUFFIX = ".json" | ||
}))) | ||
ami_assert(_ok, string.interpolate("Failed to compile contract ${ID}.json", _computed)) | ||
end |
This file contains 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,34 @@ | ||
local _computed = require "__tea.common.computed" | ||
|
||
local _ok, _metadataFile = fs.safe_read_file(_computed.METADATA_VARS.SOURCE) | ||
ami_assert(_ok, string.interpolate("Failed to load metadata from ${SOURCE}!", _computed.METADATA_VARS)) | ||
local _ok, _metadata = hjson.safe_parse(_metadataFile) | ||
ami_assert(_ok, string.interpolate("Failed to parse metadata (source: ${SOURCE})!", _computed.METADATA_VARS)) | ||
|
||
local _ok, _ocViewsFile = fs.safe_read_file(_computed.METADATA_VARS.OFFCHAIN_VIEWS) | ||
if _ok then | ||
local _ok, _ocViews = hjson.safe_parse(_ocViewsFile) | ||
if _ok then | ||
local _readyOcViews = {} | ||
local _vars = util.merge_tables(_computed.LIGO_VARS, _computed.METADATA_VARS, true) | ||
local _cmd = _computed.LIGO_VARS.LIGO .. " compile expression" .. | ||
' ${SYNTAX} ${name}${OFFCHAIN_VIEW_EXP_SUFFIX} --init-file ${FILE} --michelson-format json ${PROTOCOL_ARG}' | ||
|
||
for _, v in ipairs(_ocViews) do | ||
log_info("Compiling offchain view '${name}'...", v) | ||
local _result = proc.exec(string.interpolate(_cmd, util.merge_tables(_vars, v, true)), { stdout = "pipe" }) | ||
ami_assert(_result.exitcode == 0, string.interpolate("Failed to compile ${name}!", v)) | ||
local _code = hjson.parse(_result.stdoutStream:read("a")) | ||
local _ocv = util.clone(v, true) | ||
_ocv.implementations[1].michelsonStorageView.code = _code | ||
table.insert(_readyOcViews, _ocv) | ||
end | ||
_metadata.views = _readyOcViews | ||
else | ||
log_warn("Failed to parse offchain views definition. Offchain views wont be included in the metadata!") | ||
end | ||
else | ||
log_warn("Failed to load offchain views definition. Offchain views wont be included in the metadata!") | ||
end | ||
|
||
fs.write_file("build/metadata.json", hjson.stringify_to_json(_metadata, { indent = _computed.METADATA_VARS.INDENT and "\t", sortKeys = true })) |
Oops, something went wrong.