-
Notifications
You must be signed in to change notification settings - Fork 798
/
Copy pathnanoapi.fbs
executable file
·318 lines (271 loc) · 9.26 KB
/
nanoapi.fbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/*
Flatbuffers schema for the Nano IPC API.
This file contains IPC message definitions from which code and other artifacts are
generated.
Rules for editing this file:
- Only append or deprecate fields; never rearrange or remove fields. This ensures
binary backwards- and forwards compatibility.
- Renaming fields retain binary compatibility, but should still be considered
a breaking change in most cases. This is because the old name may be expected
in JSON messages and generated API accessors (which may lead to issues in dynamic
languages)
- Renaming a message is considered a breaking change, as the name appears in endpoints
and JSON message envelopes.
- Use 64-bit integer types only when the value fits in 2^53-1. This ensures exact
values in all supported bindings, including Javascript (which only supports the
double type) As an example, timestamps such as milliseconds-since-epoch can be
used safely.
- For integers larger than 2^53-1 where full precision is needed, use a string. Numbers
in strings are considered big int or big decimal, balances being a prominent example.
- Use the naming pattern SomeMessageName for requests, and SomeMessageNameResponse for
responses if an existing response type isn't available.
- Subscribe messages must be prefixed Topic and messages belonging to a subscription
must be prefixed Event. Using confirmations as an example, this means using the
message names TopicConfirmation and EventConfirmation respectively.
- Includes and multiple namespaces must not be used yet due to known issues with
language bindings.
- Do not use Flatbuffer structs, these are much harder to evolve and the benefits
are minor.
- Use the (required) attribute only when it's obvious it will never be optional in
the future. Required fields make it harder to obtain full compatibility.
Other considerations:
- If a message accrue many deprecations, consider making a minor-versioned message.
This should be done through nominal typing, i.e. a new message type with a suffix
indicating the version, like AccountWeight_v2_1. The response type can be an existing
type, but can also be versioned in the same manner. This naming pattern may be used
for endpoint mapping in the future, such as /api/v2_1/AccountWeight.
- If several messages need refactoring or improvements, a new API version should be
considered. This requires establishing a new endpoint (e.g. /api/v3)
New and old versions can co-exist.
Note that none of these rules apply to APIs considered internal, as these are versioned
by their enclosing binary. That is, all binaries (node, rpc, wallet, etc) using internal
APIs are expected to be upgraded at the same time and are thus versioned together. The
same relaxation applies to fields and messages considered "debug" or "experimental".
See also https://google.github.io/flatbuffers/md__schemas.html for recommended
schema evolution practices.
*/
namespace nanoapi;
/** Returns the voting weight for the given account */
table AccountWeight {
/** A nano_ address */
account: string (required);
}
/** Response to AccountWeight */
table AccountWeightResponse {
/** Voting weight as a decimal number*/
voting_weight: string (required);
}
/**
* Block subtype for state blocks.
* Note that the node makes no distinction between open and receive subtypes.
*/
enum BlockSubType: byte {
invalid = 0,
receive,
send,
change,
epoch
}
/** Block union */
union Block {
BlockState,
BlockOpen,
BlockReceive,
BlockSend,
BlockChange
}
table BlockOpen {
/** Hash of this block */
hash: string;
/** Account being opened */
account: string;
/** Hash of send block */
source: string;
/** Representative address */
representative: string;
/** Signature as a hex string */
signature: string;
/** Work is a hex string representing work. This is a string as the work value may not fit in native numeric types. */
work: string;
}
table BlockReceive {
/** Hash of this block */
hash: string;
/** Hash of previous block */
previous: string;
/** Source hash */
source: string;
/** Signature as a hex string */
signature: string;
/** Work is a hex string representing work. This is a string as the work value may not fit in native numeric types. */
work: string;
}
table BlockSend {
/** Hash of this block */
hash: string;
/** Hash of previous block */
previous: string;
/** Destination account */
destination: string;
/** Balance in raw */
balance: string;
/** Signature as a hex string */
signature: string;
/** Work is a hex string representing work. This is a string as the work value may not fit in native numeric types. */
work: string;
}
table BlockChange {
/** Hash of this block */
hash: string;
/** Hash of previous block */
previous: string;
/** Representative address */
representative: string;
/** Signature as a hex string */
signature: string;
/** Work is a hex string representing work. This is a string as the work value may not fit in native numeric types. */
work: string;
}
table BlockState {
/** Hash of this block */
hash: string;
/** Account as nano_ string */
account: string;
/** Hash of previous block */
previous: string;
/** Representative as nano_ string */
representative: string;
/** Balance in raw */
balance: string;
/** Link as a hex string */
link: string;
/** Link interpreted as a nano_ address */
link_as_account: string;
/** Signature as a hex string */
signature: string;
/** Work is a hex string representing work. This is a string as the work value may not fit in native numeric types. */
work: string;
/** Subtype of this state block */
subtype: BlockSubType;
}
/** Information about a block */
table BlockInfo {
block: Block;
}
/** Called by a service (usually an external process) to register itself */
table ServiceRegister {
service_name: string;
}
/** Request the node to send an EventServiceStop event to the given service */
table ServiceStop {
/** Name of service to stop. */
service_name: string (required);
/** If true, restart the service */
restart: bool = false;
}
/**
* Subscribe or unsubscribe to EventServiceStop events.
* The service must first have registered itself on the same session.
*/
table TopicServiceStop {
/** Set to true to unsubscribe */
unsubscribe: bool;
}
/** Sent to a service to request it to stop itself */
table EventServiceStop {
}
/**
* All subscriptions are acknowledged. Use the envelope's correlation id
* if you need to match the ack with the subscription.
*/
table EventAck {
}
/** Requested confirmation type */
enum TopicConfirmationTypeFilter : byte { all, active, active_quorum, active_confirmation_height, inactive }
/** Type of block confirmation */
enum TopicConfirmationType : byte { active_quorum, active_confirmation_height, inactive }
/** Subscribe or unsubscribe to block confirmations of type EventConfirmation */
table TopicConfirmation {
/** Set to true to unsubscribe */
unsubscribe: bool;
options: TopicConfirmationOptions;
}
table TopicConfirmationOptions {
confirmation_type_filter: TopicConfirmationTypeFilter = all;
all_local_accounts: bool;
accounts: [string];
include_block: bool = true;
include_election_info: bool = true;
}
/** Notification of block confirmation. */
table EventConfirmation {
confirmation_type: TopicConfirmationType;
account: string;
amount: string;
hash: string;
block: Block;
election_info: ElectionInfo;
}
table ElectionInfo {
duration: uint64;
time: uint64;
tally: string;
request_count: uint64;
block_count: uint64;
voter_count: uint64;
}
/** Error response. All fields are optional */
table Error {
/** Error code. May be negative or positive. */
code: int;
/** Error category code */
category: int;
/** Error message */
message: string;
}
/**
* A general purpose success response for messages that don't return a message.
* The response includes an optional message text.
*/
table Success {
message: string;
}
/** IsAlive request and response. Any node issues will be reported through an error in the envelope. */
table IsAlive {
}
/**
* A union is the idiomatic way in Flatbuffers to transmit messages of multiple types.
* All top-level message types (including response types) must be listed here.
* @warning To ensure compatibility, only append and deprecate message types.
*/
union Message {
Error,
Success,
IsAlive,
EventAck,
BlockInfo,
AccountWeight,
AccountWeightResponse,
TopicConfirmation,
EventConfirmation,
ServiceRegister,
ServiceStop,
TopicServiceStop,
EventServiceStop
}
/**
* All messages are wrapped in an envelope which contains information such as
* message type, credentials and correlation id. For responses, the message may be an Error.
*/
table Envelope {
/** Milliseconds since epoch when the message was sent. */
time: uint64;
/** An optional and arbitrary string used for authentication. The corresponding http header for api keys is "nano-api-key" */
credentials: string;
/** Correlation id is an optional and arbitrary string. The corresponding http header is "nano-correlation-id" */
correlation_id: string;
/** The contained message. A 'message_type' property will be automatically added to JSON messages. */
message: Message;
}
/** The Envelope is the type marshalled over IPC, and also serves as the top-level JSON type */
root_type Envelope;