-
Notifications
You must be signed in to change notification settings - Fork 21
/
signaturepayload.h
42 lines (33 loc) · 1.13 KB
/
signaturepayload.h
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
#define SIGNATURE_VERSION 0x81
#define ADDRESS_SEPARATOR 0xFF
#define BLOCK_HASH_SIZE 32
typedef enum { IMMORTAL_ERA = 0, MORTAL_ERA = 1 } ExtrinsicEra;
typedef struct {
uint8_t version;
uint8_t signerPublicKey[SR25519_PUBLIC_SIZE];
uint8_t sr25519Signature[SR25519_SIGNATURE_SIZE];
uint128 nonce;
ExtrinsicEra era;
} Signature;
typedef struct {
uint128 nonce;
uint8_t methodBytesLength;
uint8_t *methodBytes;
ExtrinsicEra era;
uint8_t authoringBlockHash[BLOCK_HASH_SIZE];
long serializeBinary(uint8_t *buf) {
int writtenLength = 0;
// Nonce
auto compactNonce = scale::encodeCompactInteger(nonce);
writtenLength += scale::writeCompactToBuf(compactNonce, buf + writtenLength);
// Method
memcpy(buf + writtenLength, methodBytes, methodBytesLength);
writtenLength += methodBytesLength;
// Extrinsic Era
buf[writtenLength++] = era;
// Authoring Block Hash
memcpy(buf + writtenLength, authoringBlockHash, BLOCK_HASH_SIZE);
writtenLength += BLOCK_HASH_SIZE;
return writtenLength;
}
} SignaturePayload;