Giter Club home page Giter Club logo

hype's Introduction

Hype

Production-ready Indexer framework for Terra blockchain. Allows subscribing on-chain events from Terra, and provides utilities for maintenances like back-filling previous data.

Getting Started

$ yarn add @therne/hype

Architecture Overview

Hype Diagram

Example

Subscribing CW20 Transfers in Real-Time

const hype = await createRealtimeHype();
const ancTransferFinder = createCw20TransferLogFinder('terra14z56l0fp2lsf86zy3hty2z47ezkhnthtr9yq76');

hype.subscribe('anchor-transfer', async (block) => {
  extractEventsInBlock(block, [ancTransferFinder])
    .forEach(({ txHash, event: { from, to, amount } }) => {
      console.log(`Sent ${amount} ANC from ${from} to ${to}`);
      console.log(` -> https://finder.terra.money/mainnet/tx/${txHash}`);
    });
});

await hype.start();

Indexing CW20 Transfer Logs in Real-Time

const datasource = new BlockPoller(
  new LCDBlockFetcher(),
  saveLastSyncedHeightInHivePersistence(new DynamoDBDriver({...})),
);

const hype = new Hype(datasource);
hype.subscribe(
  'cw20-transfer',
  createPersistentIndexer(Cw20TransferLog, async (block) =>
    extractEventsInBlock(block, [
      createReturningLogFinderRule(
        {
          type: 'from_contract',
          attributes: [
            ['contract_address'],
            ['action', 'transfer'],
            ['from'],
            ['to'],
            ['amount'],
          ],
        },
        (_, match) => Cw20TransferLog.create({
          token: match[0].value,
          from: match[2].value,
          to: match[3].value,
          amount: match[4].value,
        }),
      ),
    ])
  ),
);
await hype.start();

Indexing Specific Range of Blocks

Replace BlockPoller with BlockBackFiller.

const datasource = new BlockBackFiller(
  new FCDBlockFetcher('https://hive.terra.dev/graphql'),
  4980471, 4981423,
);
const hype = new Hype(datasource);

hype.subscribe('cw20-transfer', ...);
hype.start();

hype's People

Contributors

therne avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.