Update to use improved gmplugin_rebar3 #1
@@ -1,4 +1,5 @@
|
||||
.rebar3
|
||||
gajumaru
|
||||
_build
|
||||
_checkouts
|
||||
_vendor
|
||||
|
||||
@@ -14,23 +14,20 @@ all: compile
|
||||
|
||||
init: submodules
|
||||
|
||||
submodules:
|
||||
submodules: gajumaru
|
||||
git submodule init
|
||||
git submodule update
|
||||
ln -sfn $(GAJUMARU_LIB) gajumaru
|
||||
|
||||
compile:
|
||||
rebar3 compile
|
||||
|
||||
build-my-plugin: compile
|
||||
rebar3 gm_plugin
|
||||
|
||||
# adapted from gmp_ix
|
||||
build-gm-with-my-plugin: build-my-plugin
|
||||
build-gm-with-my-plugin: init compile
|
||||
cp _build/default/$(APP_NAME).ez $(GAJUMARU_LIB)/plugins
|
||||
cd $(GAJUMARU_LIB) && make prod-build
|
||||
cp -rvf gmconfig/$(TARGET_NETWORK)/gajumaru/* $(BUILD_DIR)
|
||||
|
||||
|
||||
fresh-console: build-gm-with-my-plugin console
|
||||
|
||||
console:
|
||||
|
||||
@@ -21,12 +21,15 @@ make fresh-console
|
||||
```
|
||||
|
||||
```
|
||||
(gajumaru@localhost)1> gmplugin_hello_app:hello().
|
||||
(gajumaru@localhost)1> gmplugin_hello:hello().
|
||||
"hello, world"
|
||||
(gajumaru@localhost)2> gmplugin_hello_app:network_id().
|
||||
(gajumaru@localhost)2> gmplugin_hello:network_id().
|
||||
<<"localnet">>
|
||||
(gajumaru@localhost)3> gmplugin_hello_app:height().
|
||||
(gajumaru@localhost)3> gmplugin_hello:height().
|
||||
{ok,1}
|
||||
(gajumaru@localhost)4> gmplugin_hello:top_block_hash().
|
||||
<<180,29,45,232,36,109,241,141,132,206,55,120,13,156,229,
|
||||
68,76,166,229,246,220,199,45,20,244,161,153,164,72,...>>
|
||||
```
|
||||
|
||||
|
||||
|
||||
+1
-1
Submodule lib/gajumaru updated: 752c8d0ae5...0af93a9537
+24
-5
@@ -1,16 +1,35 @@
|
||||
%%% -*- mode: erlang; erlang-indent-level: 4; indent-tabs-mode: nil -*-
|
||||
{erl_opts, [debug_info]}.
|
||||
|
||||
% there's some bug somewhere... this list must be nonempty for some reason
|
||||
%% When we want to use dependencies that are already in the gajumaru
|
||||
%% code base, we use the `{gm, App}` notation. The build plugin will
|
||||
%% consult the rebar.lock file of the gajumaru root and fetch the
|
||||
%% right version of `App`.
|
||||
%%
|
||||
{deps, [
|
||||
{gmserialization, {gm, gmserialization}}
|
||||
]}.
|
||||
|
||||
{project_apps_dir, "lib/gajumaru/apps"}.
|
||||
{plugins,
|
||||
[
|
||||
{gmplugin_rebar3,
|
||||
{git, "https://git.qpq.swiss/QPQ-AG/gmplugin_rebar3.git",
|
||||
{branch,"master"}}}
|
||||
]}.
|
||||
|
||||
{plugins, [
|
||||
{gmplugin_rebar3, {git, "https://git.qpq.swiss/QPQ-AG/gmplugin_rebar3.git", {branch,"master"}}}
|
||||
]}.
|
||||
%% These provider hooks inform the gmplugin_rebar3 provider.
|
||||
%% The pre-erlc_compile hook is needed if our code includes .hrl files
|
||||
%% from the gajumaru core (which it does, for demo purposes).
|
||||
%% The post-compile hook produces the packaged plugin.
|
||||
%%
|
||||
{provider_hooks, [
|
||||
{pre, [{erlc_compile, gm_setup}]},
|
||||
{post, [{compile, gm_plugin}]}
|
||||
]}.
|
||||
|
||||
%% This gajumaru root is used unless we run `make init`, which updates the
|
||||
%% submodules and creates a top-level symlink to lib/gajumaru.
|
||||
%%
|
||||
{gajumaru_root, {git, "https://git.qpq.swiss/QPQ-AG/gajumaru", "master"}}.
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
%%% -*- mode:erlang; erlang-indent-level: 4; indent-tabs-mode: nil -*-
|
||||
-module(gmplugin_hello).
|
||||
|
||||
-export([
|
||||
hello/0,
|
||||
network_id/0,
|
||||
height/0,
|
||||
top_block_hash/0
|
||||
]).
|
||||
|
||||
%% When including a .hrl file from the gajumaru core, we simply give
|
||||
%% the name (not -include_lib(), as this would require us to build
|
||||
%% the code base first.) The build plugin ensures that all core
|
||||
%% includes are available in the compiler's include path.
|
||||
%%
|
||||
-include("blocks.hrl").
|
||||
|
||||
-spec hello() -> string().
|
||||
hello() ->
|
||||
"hello, world".
|
||||
|
||||
-spec network_id() -> binary().
|
||||
network_id() ->
|
||||
aec_governance:get_network_id().
|
||||
|
||||
|
||||
-spec height() -> {ok, Height :: pos_integer()}
|
||||
| {error, no_top_block}.
|
||||
height() ->
|
||||
case aec_chain:top_height() of
|
||||
undefined -> {error, no_top_block};
|
||||
Height -> {ok, Height}
|
||||
end.
|
||||
|
||||
-spec top_block_hash() -> block_header_hash().
|
||||
top_block_hash() ->
|
||||
aec_chain:top_block_hash().
|
||||
@@ -10,42 +10,8 @@
|
||||
|
||||
-export([start/2, stop/1]).
|
||||
|
||||
% tests
|
||||
-export([
|
||||
hello/0,
|
||||
network_id/0,
|
||||
height/0
|
||||
]).
|
||||
|
||||
start(_StartType, _StartArgs) ->
|
||||
gmplugin_hello_sup:start_link().
|
||||
|
||||
stop(_State) ->
|
||||
ok.
|
||||
|
||||
%% internal functions
|
||||
|
||||
|
||||
%%
|
||||
-spec hello() -> string().
|
||||
|
||||
hello() ->
|
||||
"hello, world".
|
||||
|
||||
|
||||
|
||||
-spec network_id() -> binary().
|
||||
|
||||
network_id() ->
|
||||
aec_governance:get_network_id().
|
||||
|
||||
|
||||
|
||||
-spec height() -> {ok, Height :: pos_integer()}
|
||||
| {error, no_top_block}.
|
||||
|
||||
height() ->
|
||||
case aec_chain:top_height() of
|
||||
undefined -> {error, no_top_block};
|
||||
Height -> {ok, Height}
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user