Let non-zx projects call contract_create*
This commit is contained in:
+20
-6
@@ -1213,21 +1213,35 @@ bundle_source(Compiled) ->
|
|||||||
|
|
||||||
bundle_source2(Source, Compiled) ->
|
bundle_source2(Source, Compiled) ->
|
||||||
File = unicode:characters_to_list(maps:get(contract_name, Compiled, "contract.aes")),
|
File = unicode:characters_to_list(maps:get(contract_name, Compiled, "contract.aes")),
|
||||||
<<RN:(8 * 8)>> = crypto:strong_rand_bytes(8),
|
TempDir = temp_dir(),
|
||||||
Rand = integer_to_binary(RN, 36),
|
|
||||||
TmpDir = filename:join(zx_lib:path(tmp), Rand),
|
|
||||||
TgzName = File ++ ".tgz",
|
TgzName = File ++ ".tgz",
|
||||||
TarGzPath = filename:join(TmpDir, TgzName),
|
TarGzPath = filename:join(TempDir, TgzName),
|
||||||
ok = filelib:ensure_dir(TarGzPath),
|
ok = filelib:ensure_dir(TarGzPath),
|
||||||
{ok, CWD} = file:get_cwd(),
|
{ok, CWD} = file:get_cwd(),
|
||||||
ok = file:set_cwd(TmpDir),
|
ok = file:set_cwd(TempDir),
|
||||||
ok = erl_tar:create(TarGzPath, [{File, Source}], [compressed]),
|
ok = erl_tar:create(TarGzPath, [{File, Source}], [compressed]),
|
||||||
{ok, TgzBin} = file:read_file(TarGzPath),
|
{ok, TgzBin} = file:read_file(TarGzPath),
|
||||||
ok = file:set_cwd(CWD),
|
ok = file:set_cwd(CWD),
|
||||||
ok = file:del_dir_r(TmpDir),
|
ok = file:del_dir_r(TempDir),
|
||||||
{ok, Hash} = eblake2:blake2b(32, TgzBin),
|
{ok, Hash} = eblake2:blake2b(32, TgzBin),
|
||||||
Compiled#{contract_source => TgzBin, source_hash => Hash}.
|
Compiled#{contract_source => TgzBin, source_hash => Hash}.
|
||||||
|
|
||||||
|
temp_dir() ->
|
||||||
|
case erlang:function_exported(zx_lib, path, 3) of
|
||||||
|
true ->
|
||||||
|
TS = integer_to_list(erlang:system_time()),
|
||||||
|
filename:join(zx_lib:path(tmp, "otpr", "hakuzaru"), TS);
|
||||||
|
false ->
|
||||||
|
temp_dir(os:type())
|
||||||
|
end.
|
||||||
|
|
||||||
|
temp_dir({unix, _}) ->
|
||||||
|
string:trim(os:cmd("mktemp -d"));
|
||||||
|
temp_dir({win32, _}) ->
|
||||||
|
Temp = os:getenv("TEMP"),
|
||||||
|
TS = integer_to_list(erlang:system_time()),
|
||||||
|
filename:join([Temp, "hakuzaru", TS]).
|
||||||
|
|
||||||
|
|
||||||
-spec read_aci(Path) -> Result
|
-spec read_aci(Path) -> Result
|
||||||
when Path :: file:filename(),
|
when Path :: file:filename(),
|
||||||
|
|||||||
Reference in New Issue
Block a user