How to use hsd - 10 common examples

To help you get started, we’ve selected a few hsd examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github HandshakeAlliance / testnet-faucet / src / handlers / withdraw.js View on Github external
async function withdrawHandler(request, h) {
  const wallet = getWallet();

  //Get balance, and conver to HNS units (BigNumber)
  let balanceData = await wallet.getBalance();
  let balance = convertToHNS(balanceData.confirmed);

  //Calculate available to withdraw
  let available = calculateWithdraw(balance);

  available = convertToHNS(available, false);

  let address = new Address(request.payload.address);

  //Expect this to be in subunit
  let amount = request.payload.amount;

  let tx;

  //Check if the address is valid.
  if (!address.isValid()) {
    return h.response("This address is not valid").code(401);
  }

  if (amount > available || amount == 0) {
    return h
      .response("You cannot withdraw this much. Please try again.")
      .code(401);
  }
github HandshakeAlliance / HNScan / src / handlers / search.js View on Github external
if (height <= tip && height >= 0) {
      let result = { type: "Block", url: `/block/${height}` };

      results.push(result);
    }
  }

  if (txHash.test(search)) {
    let result = { type: "Transaction", url: `/tx/${search}` };
    results.push(result);
  }

  let address;

  try {
    address = new Address(search);
  } catch (e) {
    //Do nothing.
  }

  if (address) {
    if (address.isValid()) {
      let result = { type: "Address", url: `/address/${search}` };
      results.push(result);
    }
  }

  if (rules.verifyString(search)) {
    let result = { type: "Name", url: `/name/${search}` };
    results.push(result);
  }
github HandshakeAlliance / HNScan / src / handlers / tools / airdrop.js View on Github external
async function airdropHandler(request, h) {
  const client = getClient();
  const nomenclate = getNomenclate();

  let info;

  try {
    info = await client.getInfo();
  } catch (e) {
    console.log(e);
  }

  let network = Network.get(info.network);
  let airdropKey = network.keys.airdrop;

  const airdropAddr = Address.fromHash(airdropKey, 0);
  let balance;
  let history;
  try {
    balance = await nomenclate.getAddressBalance(
      airdropAddr.toString(info.network)
    );

    history = await nomenclate.getAddressHistory(
      airdropAddr.toString(info.network)
    );
  } catch (e) {
    console.log(e);
  }
github HandshakeAlliance / HNScan / src / handlers / tools / airdrop.js View on Github external
async function airdropHandler(request, h) {
  const client = getClient();
  const nomenclate = getNomenclate();

  let info;

  try {
    info = await client.getInfo();
  } catch (e) {
    console.log(e);
  }

  let network = Network.get(info.network);
  let airdropKey = network.keys.airdrop;

  const airdropAddr = Address.fromHash(airdropKey, 0);
  let balance;
  let history;
  try {
    balance = await nomenclate.getAddressBalance(
      airdropAddr.toString(info.network)
    );

    history = await nomenclate.getAddressHistory(
      airdropAddr.toString(info.network)
    );
  } catch (e) {
    console.log(e);
  }

  const original = balance.received;
  const spent = balance.spent;
github HandshakeAlliance / HNScan / src / util / clients.js View on Github external
const config = require("config");
const { WalletClient, NodeClient } = require("hs-client");
const NomenclateClient = require("nomenclate-js");

const { Network } = require("hsd");
const network = Network.get(config.get("node-network"));

const walletOptions = {
  network: network.type,
  host: config.get("node-host"),
  port: network.walletPort,
  apiKey: config.get("node-api-key")
};

const clientOptions = {
  host: config.get("node-host"),
  network: network.type,
  port: network.rpcPort,
  apiKey: config.get("node-api-key")
};

const nomenclateOptions = {