Current section
Files
Jump to
Current section
Files
src/glupbit@exchange@service.erl
-module(glupbit@exchange@service).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/glupbit/exchange/service.gleam").
-export([get_wallet_status/1, list_api_keys/1, list_travelrule_vasps/1, verify_travelrule_by_uuid/3, verify_travelrule_by_txid/5]).
-export_type([wallet_status/0, api_key_info/0, vasp/0, travel_rule_result/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(" Service information — wallet status, API keys, travel rule.\n").
-type wallet_status() :: {wallet_status,
binary(),
binary(),
gleam@option:option(binary()),
gleam@option:option(integer()),
gleam@option:option(binary()),
gleam@option:option(integer())}.
-type api_key_info() :: {api_key_info, binary(), binary()}.
-type vasp() :: {vasp, binary(), binary(), boolean(), boolean()}.
-type travel_rule_result() :: {travel_rule_result, binary(), binary(), binary()}.
-file("src/glupbit/exchange/service.gleam", 128).
-spec wallet_status_decoder() -> gleam@dynamic@decode:decoder(wallet_status()).
wallet_status_decoder() ->
gleam@dynamic@decode:field(
<<"currency"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Currency) ->
gleam@dynamic@decode:field(
<<"wallet_state"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Wallet_state) ->
gleam@dynamic@decode:optional_field(
<<"block_state"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder, fun gleam@dynamic@decode:decode_string/1}
),
fun(Block_state) ->
gleam@dynamic@decode:optional_field(
<<"block_height"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_int/1}
),
fun(Block_height) ->
gleam@dynamic@decode:optional_field(
<<"block_updated_at"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_string/1}
),
fun(Block_updated_at) ->
gleam@dynamic@decode:optional_field(
<<"block_elapsed_minutes"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_int/1}
),
fun(Block_elapsed_minutes) ->
gleam@dynamic@decode:success(
{wallet_status,
Currency,
Wallet_state,
Block_state,
Block_height,
Block_updated_at,
Block_elapsed_minutes}
)
end
)
end
)
end
)
end
)
end
)
end
).
-file("src/glupbit/exchange/service.gleam", 48).
?DOC(
" Get wallet deposit/withdrawal service status.\n"
" GET /status/wallet\n"
).
-spec get_wallet_status(glupbit@client:auth_client()) -> {ok,
glupbit@types:api_response(list(wallet_status()))} |
{error, glupbit@types:api_error()}.
get_wallet_status(C) ->
glupbit@client:auth_get(
C,
<<"/status/wallet"/utf8>>,
[],
gleam@dynamic@decode:list(wallet_status_decoder())
).
-file("src/glupbit/exchange/service.gleam", 161).
-spec api_key_info_decoder() -> gleam@dynamic@decode:decoder(api_key_info()).
api_key_info_decoder() ->
gleam@dynamic@decode:field(
<<"access_key"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Access_key) ->
gleam@dynamic@decode:field(
<<"expire_at"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Expire_at) ->
gleam@dynamic@decode:success(
{api_key_info, Access_key, Expire_at}
)
end
)
end
).
-file("src/glupbit/exchange/service.gleam", 56).
?DOC(
" List API keys and their expiration dates.\n"
" GET /api_keys\n"
).
-spec list_api_keys(glupbit@client:auth_client()) -> {ok,
glupbit@types:api_response(list(api_key_info()))} |
{error, glupbit@types:api_error()}.
list_api_keys(C) ->
glupbit@client:auth_get(
C,
<<"/api_keys"/utf8>>,
[],
gleam@dynamic@decode:list(api_key_info_decoder())
).
-file("src/glupbit/exchange/service.gleam", 167).
-spec vasp_decoder() -> gleam@dynamic@decode:decoder(vasp()).
vasp_decoder() ->
gleam@dynamic@decode:field(
<<"vasp_name"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Vasp_name) ->
gleam@dynamic@decode:field(
<<"vasp_uuid"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Vasp_uuid) ->
gleam@dynamic@decode:field(
<<"depositable"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_bool/1},
fun(Depositable) ->
gleam@dynamic@decode:field(
<<"withdrawable"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_bool/1},
fun(Withdrawable) ->
gleam@dynamic@decode:success(
{vasp,
Vasp_name,
Vasp_uuid,
Depositable,
Withdrawable}
)
end
)
end
)
end
)
end
).
-file("src/glupbit/exchange/service.gleam", 64).
?DOC(
" List travel rule VASPs.\n"
" GET /travel_rule/vasps\n"
).
-spec list_travelrule_vasps(glupbit@client:auth_client()) -> {ok,
glupbit@types:api_response(list(vasp()))} |
{error, glupbit@types:api_error()}.
list_travelrule_vasps(C) ->
glupbit@client:auth_get(
C,
<<"/travel_rule/vasps"/utf8>>,
[],
gleam@dynamic@decode:list(vasp_decoder())
).
-file("src/glupbit/exchange/service.gleam", 175).
-spec travelrule_result_decoder() -> gleam@dynamic@decode:decoder(travel_rule_result()).
travelrule_result_decoder() ->
gleam@dynamic@decode:field(
<<"deposit_uuid"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Deposit_uuid) ->
gleam@dynamic@decode:field(
<<"verification_result"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Verification_result) ->
gleam@dynamic@decode:field(
<<"deposit_state"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Deposit_state) ->
gleam@dynamic@decode:success(
{travel_rule_result,
Deposit_uuid,
Verification_result,
Deposit_state}
)
end
)
end
)
end
).
-file("src/glupbit/exchange/service.gleam", 72).
?DOC(
" Verify travel rule by deposit UUID.\n"
" POST /travel_rule/deposit/uuid\n"
).
-spec verify_travelrule_by_uuid(
glupbit@client:auth_client(),
binary(),
binary()
) -> {ok, glupbit@types:api_response(travel_rule_result())} |
{error, glupbit@types:api_error()}.
verify_travelrule_by_uuid(C, Deposit_uuid, Vasp_uuid) ->
Body = gleam@json:object(
[{<<"deposit_uuid"/utf8>>, gleam@json:string(Deposit_uuid)},
{<<"vasp_uuid"/utf8>>, gleam@json:string(Vasp_uuid)}]
),
Params = [{<<"deposit_uuid"/utf8>>, Deposit_uuid},
{<<"vasp_uuid"/utf8>>, Vasp_uuid}],
glupbit@client:auth_post(
C,
<<"/travel_rule/deposit/uuid"/utf8>>,
Body,
Params,
travelrule_result_decoder()
).
-file("src/glupbit/exchange/service.gleam", 97).
?DOC(
" Verify travel rule by transaction ID.\n"
" POST /travel_rule/deposit/txid\n"
).
-spec verify_travelrule_by_txid(
glupbit@client:auth_client(),
binary(),
binary(),
binary(),
binary()
) -> {ok, glupbit@types:api_response(travel_rule_result())} |
{error, glupbit@types:api_error()}.
verify_travelrule_by_txid(C, Vasp_uuid, Txid, Currency, Net_type) ->
Body = gleam@json:object(
[{<<"vasp_uuid"/utf8>>, gleam@json:string(Vasp_uuid)},
{<<"txid"/utf8>>, gleam@json:string(Txid)},
{<<"currency"/utf8>>, gleam@json:string(Currency)},
{<<"net_type"/utf8>>, gleam@json:string(Net_type)}]
),
Params = [{<<"vasp_uuid"/utf8>>, Vasp_uuid},
{<<"txid"/utf8>>, Txid},
{<<"currency"/utf8>>, Currency},
{<<"net_type"/utf8>>, Net_type}],
glupbit@client:auth_post(
C,
<<"/travel_rule/deposit/txid"/utf8>>,
Body,
Params,
travelrule_result_decoder()
).