upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/main/tollgate_platform.c
diff options
context:
space:
mode:
Diffstat (limited to 'main/tollgate_platform.c')
-rw-r--r--main/tollgate_platform.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/main/tollgate_platform.c b/main/tollgate_platform.c
new file mode 100644
index 0000000..c992ea1
--- /dev/null
+++ b/main/tollgate_platform.c
@@ -0,0 +1,64 @@
1#include "tollgate_platform.h"
2#include "tollgate_core.h"
3#include "config.h"
4#include "esp_log.h"
5#include "esp_timer.h"
6#include "freertos/FreeRTOS.h"
7#include "freertos/task.h"
8
9static const char *TAG = "tollgate_platform";
10
11static uint16_t platform_get_price_sats(void)
12{
13 const tollgate_config_t *cfg = tollgate_config_get();
14 return cfg ? (uint16_t)cfg->price_per_step : 21;
15}
16
17static int32_t platform_get_step_ms(void)
18{
19 const tollgate_config_t *cfg = tollgate_config_get();
20 return cfg ? (int32_t)cfg->step_size_ms : 60000;
21}
22
23static const char *platform_get_mint_url(void)
24{
25 const tollgate_config_t *cfg = tollgate_config_get();
26 return cfg ? cfg->mint_url : "https://testnut.cashu.space";
27}
28
29static const char *platform_get_metric(void)
30{
31 const tollgate_config_t *cfg = tollgate_config_get();
32 return cfg ? cfg->metric : "milliseconds";
33}
34
35static int32_t platform_get_step_bytes(void)
36{
37 const tollgate_config_t *cfg = tollgate_config_get();
38 return cfg ? (int32_t)cfg->step_size_bytes : 22020096;
39}
40
41static int64_t platform_get_time_ms(void)
42{
43 return (int64_t)xTaskGetTickCount() * portTICK_PERIOD_MS;
44}
45
46static bool platform_spend_proofs(const char *raw_token_json)
47{
48 (void)raw_token_json;
49 return true;
50}
51
52const tollgate_platform_t *tollgate_get_platform(void)
53{
54 static const tollgate_platform_t platform = {
55 .get_price_sats = platform_get_price_sats,
56 .get_step_ms = platform_get_step_ms,
57 .get_mint_url = platform_get_mint_url,
58 .get_metric = platform_get_metric,
59 .get_step_bytes = platform_get_step_bytes,
60 .get_time_ms = platform_get_time_ms,
61 .spend_proofs = platform_spend_proofs,
62 };
63 return &platform;
64}