Basic Implementation

LiquidStorage Consumer Example Contract used in unit tests

./zeus_boxes/contracts/eos/storageconsumer/storageconsumer.cpp
The consumer contract is a great starting point for playing around with the LiquidStorage service. This sample contract uses LiquidAccounts as an option, but the service may also be used with regular EOS accounts.
1
/* DELAY REMOVAL OF USER DATA INTO VRAM */
2
/* ALLOWS FOR QUICKER ACCESS TO USER DATA WITHOUT THE NEED TO WARM DATA UP */
3
#define VACCOUNTS_DELAYED_CLEANUP 120
4
​
5
/* ADD NECESSARY LIQUIDACCOUNT / VRAM INCLUDES */
6
#include "../dappservices/ipfs.hpp"
7
#include "../dappservices/multi_index.hpp"
8
#include "../dappservices/vaccounts.hpp"
9
#include <eosio/singleton.hpp>
10
​
11
/* ADD LIQUIDACCOUNT / VRAM RELATED ACTIONS */
12
#define DAPPSERVICES_ACTIONS() \
13
XSIGNAL_DAPPSERVICE_ACTION \
14
IPFS_DAPPSERVICE_ACTIONS \
15
VACCOUNTS_DAPPSERVICE_ACTIONS
16
#define DAPPSERVICE_ACTIONS_COMMANDS() \
17
IPFS_SVC_COMMANDS() VACCOUNTS_SVC_COMMANDS()
18
​
19
#define CONTRACT_NAME() storageconsumer
20
​
21
CONTRACT_START()
22
​
23
/* THE storagecfg TABLE STORES STORAGE PARAMS */
24
TABLE storagecfg {
25
// all measurements in bytes
26
uint64_t max_file_size_in_bytes = UINT64_MAX; // max file size in bytes that can be uploaded at a time, default 10mb
27
uint64_t global_upload_limit_per_day = UINT64_MAX; // max upload limit in bytes per day for EOS account, default 1 GB
28
uint64_t vaccount_upload_limit_per_day = UINT64_MAX; // max upload limit in bytes per day for LiquidAccounts, default 10 MB
29
};
30
typedef eosio::singleton<"storagecfg"_n, storagecfg> storagecfg_t;
31
​
32
/* SET PARAMS FOR storagecfg TABLE */
33
ACTION setstoragecfg(const uint64_t &max_file_size_in_bytes,
34
const uint64_t &global_upload_limit_per_day,
35
const uint64_t &vaccount_upload_limit_per_day) {
36
require_auth(get_self());
37
storagecfg_t storagecfg_table(get_self(), get_self().value);
38
auto storagecfg = storagecfg_table.get_or_default();
39
​
40
storagecfg.max_file_size_in_bytes = max_file_size_in_bytes;
41
storagecfg.global_upload_limit_per_day = global_upload_limit_per_day;
42
storagecfg.vaccount_upload_limit_per_day = vaccount_upload_limit_per_day;
43
​
44
storagecfg_table.set(storagecfg, get_self());
45
}
46
​
47
/* THE FOLLOWING STRUCT DEFINES THE PARAMS THAT MUST BE PASSED FOR A LIQUIDACCOUNT TRX */
48
struct dummy_action_hello {
49
name vaccount;
50
uint64_t b;
51
uint64_t c;
52
​
53
EOSLIB_SERIALIZE(dummy_action_hello, (vaccount)(b)(c))
54
};
55
​
56
/* DATA IS PASSED AS PAYLOADS INSTEAD OF INDIVIDUAL PARAMS */
57
[[eosio::action]] void hello(dummy_action_hello payload) {
58
/* require_vaccount is the equivalent of require_auth for EOS */
59
require_vaccount(payload.vaccount);
60
​
61
print("hello from ");
62
print(payload.vaccount);
63
print(" ");
64
print(payload.b + payload.c);
65
print("\n");
66
}
67
​
68
/* EACH ACTION MUST HAVE A STRUCT THAT DEFINES THE PAYLOAD SYNTAX TO BE PASSED */
69
VACCOUNTS_APPLY(((dummy_action_hello)(hello)))
70
​
71
CONTRACT_END((hello)(regaccount)(setstoragecfg)(xdcommit)(xvinit))
Copied!
Last modified 1yr ago
Copy link