Demux implementations to read blocks, actions and events from Minter blockchain.
# Using yarn
yarn add demux-minter
# Using npm
npm install --save demux-minter
This library provides the following classes:
-
AbstractMinterActionReader
: Abstract class used for implementing your own Action Readers -
AbstractMinterActionHandler
: Abstract class used for implementing your own Action Handlers -
MinterActionReader
: Base class that implements a ready-to-use Action Reader -
MinterActionWatcher
: Base class that implements a ready-to-use Action Watcher
For action types (transactions and events) description we use human-readable names:
Transactions types
Send
- 0x01SellCoin
- 0x02SellAllCoin
- 0x03BuyCoin
- 0x04CreateCoin
- 0x05DeclareCandidacy
- 0x06Delegate
- 0x07Unbond
- 0x08RedeemCheck
- 0x09SetCandidateOnline
- 0x0ASetCandidateOffline
- 0x0BCreateMultisig
- 0x0CMultisend
- 0x0DEditCandidate
- 0x0E
Reward
- minter/RewardEventSlash
- minter/SlashEvent
import { AbstractMinterActionHandler } from "demux-minter";
const state = {
blockHash: "",
blockHeight: 0,
sendCount: 0,
delegateCount: 0
};
class MinterActionHandler extends AbstractMinterActionHandler {
async handleWithState(handle) {
await handle(state);
}
async loadIndexState() {
return state;
}
async updateIndexState(state, block, context) {
state.blockHeight = block.blockInfo.blockHeight;
state.blockHash = block.blockInfo.blockHash;
}
async setup() {}
}
import { MinterActionWatcher, MinterActionReader } from "demux-minter";
import MinterActionHandler from "./MinterActionHandler";
function sendUpdater(state, payload, blockInfo, context) {
state.sendCount += 1;
}
function delegateUpdater(state, payload, blockInfo, context) {
state.delegateCount += 1;
}
function sendEffect(state, payload, blockInfo, context) {
console.log("Send", state.sendCount);
}
function delegateEffect(state, payload, blockInfo, context) {
console.log("Delegate", state.delegateCount);
}
const updaters = [
{
type: "Send",
updater: sendUpdater
},
{
type: "Delegate",
updater: delegateUpdater
}
];
const effects = [
{
type: "Send",
effect: sendEffect
},
{
type: "Delegate",
effect: delegateEffect
}
];
const actionReader = new MinterActionReader({
minterEndpoint: "https://minter-node-1.testnet.minter.network:8841",
startAtBlock: 0
});
const actionHandler = new MinterActionHandler(updaters, effects);
const actionWatcher = new MinterActionWatcher({ actionReader, actionHandler });
actionWatcher.watch();