Skip to content

Commit

Permalink
list-protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
cryi committed Apr 13, 2024
1 parent 85192b3 commit 0c627f2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
11 changes: 11 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ To use TezBox, you need to have OCI compatible container runtime installed on yo
```bash
# to run chain with the O protocol
docker run -it -p 0.0.0.0:8732:8732 ghcr.io/tez-capital/tezbox:tezos-v19.1 oxfordbox
# or to run in the background
docker run -d -p 0.0.0.0:8732:8732 ghcr.io/tez-capital/tezbox:tezos-v19.1 oxfordbox

# to run chain with the P protocol
docker run -it -p 0.0.0.0:8732:8732 ghcr.io/tez-capital/tezbox:tezos-v20.0-rc1 parisbox
# or to run in the background
docker run -d -p 0.0.0.0:8732:8732 ghcr.io/tez-capital/tezbox:tezos-v20.0-rc1 parisbox
```
You can list available protocols with the following command:
```bash
# docker run -it <image> list-protocols
docker run -it --entrypoint tezbox ghcr.io/tez-capital/tezbox:tezos-v19.1 list-protocols
```

### Configuration
Expand All @@ -22,6 +31,8 @@ All configuration files are located in the `/tezbox/configuration` directory and

NOTE: *It is not possible to define bootstrap_accounts through sandbox-parameters. Use `.../configuration/bakers.hjson` instead.*

NOTE: **Do not edit or mount configuration files in the `/tezbox/context` directory. They are generated automatically and should not be modified manually.**

#### Accounts

By default tezbox comes with these accounts:
Expand Down
14 changes: 9 additions & 5 deletions src/box/context.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local hjson = require "hjson"
local constants = require "box.constants"

local context = {
protocolMapping = {},
protocols = {}
}

Expand Down Expand Up @@ -76,6 +77,7 @@ function context.build()
asDirEntries = false,
}) --[=[@as string[]]=]

local protocolMapping = {}
local protocols = {}
for _, protocolDirectory in ipairs(protocolDirectories) do
local protocolFile = path.combine(protocolDirectory, constants.protocolFileId)
Expand All @@ -85,7 +87,7 @@ function context.build()
log_warn("valid protocol id not found in protocol file: " .. protocolFile .. ", skipping")
goto continue
end
if protocols[protocol.id] then
if protocolMapping[protocol.id] then
log_warn("duplicate protocol id found: " .. protocol.id .. ", skipping")
goto continue
end
Expand All @@ -100,21 +102,23 @@ function context.build()

protocol.path = protocolDirectory

protocols[string.lower(protocol.id)] = protocol
protocols[string.lower(protocol.hash)] = protocol
protocolMapping[string.lower(protocol.id)] = protocol
protocolMapping[string.lower(protocol.hash)] = protocol
protocols[protocol.id] = protocol
for _, alias in ipairs(protocol.aliases or {}) do
local alias = string.lower(alias)
if protocols[alias] then
if protocolMapping[alias] then
log_warn("duplicate protocol alias found: " .. alias .. ", skipping")
goto continue
end
protocols[alias] = protocol
protocolMapping[alias] = protocol
::continue::
end

::continue::
end

context.protocolMapping = protocolMapping
context.protocols = protocols

-- create sandbox.json
Expand Down
13 changes: 11 additions & 2 deletions src/box/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function core.initialize(protocol, options)
octez.reset() -- reset octez state
context.build() -- rebuild context

local proto = context.protocols[protocol] --[[@as ProtocolDefinition?]]
local proto = context.protocolMapping[protocol] --[[@as ProtocolDefinition?]]
if not proto then
log_error("protocol " .. protocol .. " not found in context")
os.exit(1)
Expand Down Expand Up @@ -168,7 +168,6 @@ function core.initialize(protocol, options)
account.pk,
tostring(account.balance)
})

::continue::
end

Expand Down Expand Up @@ -220,6 +219,16 @@ function core.initialize(protocol, options)
fs.write_file(initializedProtocolFilePath, protocol)
end

function core.list_protocols()
context.build() -- rebuild context

local protocols = context.protocols
for protocol, protocolDetail in pairs(protocols) do
local aliases = util.merge_arrays({ protocolDetail.id, protocolDetail.short, protocolDetail.hash }, protocolDetail.aliases or {})
print(protocol .. " (available as: " .. string.join(", ", aliases) .. ")")
end
end

function core.run()
error("not implemented")
-- // TODO: run for setup without container
Expand Down
5 changes: 5 additions & 0 deletions src/tezbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ if args.command == "init" or args.command == "initialize" then
os.exit(0)
end

if args.command == "list-protocols" then
core.list_protocols()
os.exit(0)
end

if args.command == "run" then
core.run()
os.exit(0)
Expand Down
2 changes: 1 addition & 1 deletion src/version-info.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local TEZBOX_VERSIOn = "0.1.1"
local TEZBOX_VERSIOn = "0.1.2"

return {
VERSION = TEZBOX_VERSIOn,
Expand Down

0 comments on commit 0c627f2

Please sign in to comment.