-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.js
56 lines (49 loc) · 2.15 KB
/
handler.js
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
'use strict';
const { TransactionHandler } = require('sawtooth-sdk/processor/handler');
const { InvalidTransaction } = require('sawtooth-sdk/processor/exceptions');
const { decode } = require('./services/encoding');
const FAMILY_NAME = 'cryptomoji';
const FAMILY_VERSION = '0.1';
const NAMESPACE = '5f4d76';
/**
* A Cryptomoji specific version of a Hyperledger Sawtooth Transaction Handler.
*/
class MojiHandler extends TransactionHandler {
/**
* The constructor for a TransactionHandler simply registers it with the
* validator, declaring which family name, versions, and namespaces it
* expects to handle. We'll fill this one in for you.
*/
constructor () {
console.log('Initializing cryptomoji handler with namespace:', NAMESPACE);
super(FAMILY_NAME, [ FAMILY_VERSION ], [ NAMESPACE ]);
}
/**
* The apply method is where the vast majority of all the work of a
* transaction processor happens. It will be called once for every
* transaction, passing two objects: a transaction process request ("txn" for
* short) and state context.
*
* Properties of `txn`:
* - txn.payload: the encoded payload sent from your client
* - txn.header: the decoded TransactionHeader for this transaction
* - txn.signature: the hex signature of the header
*
* Methods of `context`:
* - context.getState(addresses): takes an array of addresses and returns
* a Promise which will resolve with the requested state. The state
* object will have keys which are addresses, and values that are encoded
* state resources.
* - context.setState(updates): takes an update object and returns a
* Promise which will resolve with an array of the successfully
* updated addresses. The updates object should have keys which are
* addresses, and values which are encoded state resources.
* - context.deleteState(addresses): deletes the state for the passed
* array of state addresses. Only needed if attempting the extra credit.
*/
apply (txn, context) {
// Enter your solution here
// (start by decoding your payload and checking which action it has)
}
}
module.exports = MojiHandler;