swarm测试极简指南bee 0.5.3支票的兑现脚本

Posted weixin_46596227

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swarm测试极简指南bee 0.5.3支票的兑现脚本相关的知识,希望对你有一定的参考价值。

0.5.3 源码

#1/usr/bin/env sh
DEBUG_API=http://localhost:1635
MIN_AMOUNT=1000

function getPeers() {
  curl -s "$DEBUG_API/chequebook/cheque" | jq -r '.lastcheques | .[].peer'
}

function getCumulativePayout() {
  local peer=$1
  local cumulativePayout=$(curl -s "$DEBUG_API/chequebook/cheque/$peer" | jq '.lastreceived.payout')
  if [ $cumulativePayout == null ]
  then
    echo 0
  else
    echo $cumulativePayout
  fi
}

function getLastCashedPayout() {
  local peer=$1
  local cashout=$(curl -s "$DEBUG_API/chequebook/cashout/$peer" | jq '.cumulativePayout')
  if [ $cashout == null ]
  then
    echo 0
  else
    echo $cashout
  fi
}

function getUncashedAmount() {
  local peer=$1
  local cumulativePayout=$(getCumulativePayout $peer)
  if [ $cumulativePayout == 0 ]
  then
    echo 0
    return
  fi

  cashedPayout=$(getLastCashedPayout $peer)
  let uncashedAmount=$cumulativePayout-$cashedPayout
  echo $uncashedAmount
}

function cashout() {
  local peer=$1
  txHash=$(curl -s -XPOST "$DEBUG_API/chequebook/cashout/$peer" | jq -r .transactionHash) 

  echo cashing out cheque for $peer in transaction $txHash >&2

  result="$(curl -s $DEBUG_API/chequebook/cashout/$peer | jq .result)"
  while [ "$result" == "null" ]
  do
    sleep 5
    result=$(curl -s $DEBUG_API/chequebook/cashout/$peer | jq .result)
  done
}

function cashoutAll() {
  local minAmount=$1
  for peer in $(getPeers)
  do
    local uncashedAmount=$(getUncashedAmount $peer)
    if (( "$uncashedAmount" > $minAmount ))
    then
      echo "uncashed cheque for $peer ($uncashedAmount uncashed)" >&2
      cashout $peer
    fi
  done
}

function listAllUncashed() {
  for peer in $(getPeers)
  do
    local uncashedAmount=$(getUncashedAmount $peer)
    if (( "$uncashedAmount" > 0 ))
    then
      echo $peer $uncashedAmount
    fi
  done
}

case $1 in
cashout)
  cashout $2
  ;;
cashout-all)
  cashoutAll $MIN_AMOUNT
  ;;
list-uncashed|*)
  listAllUncashed
  ;;
esac

将文件保存为:cashout.sh

使用方法

查票命令

sudo sh ./cashout.sh

兑票命令

sudo sh ./cashout.sh  cashout-all

以上是关于swarm测试极简指南bee 0.5.3支票的兑现脚本的主要内容,如果未能解决你的问题,请参考以下文章

swarm测试极简指南Bee Clef 是什么?

swarm测试极简指南bee 矿机节点如何快速迁移?

swarm测试极简指南如何备份保管好你的Bee矿机数据

swarm测试极简指南矿机的关键目录都在哪里?

swarm测试极简指南bee矿机的网络特点与惩罚机制

swarm测试极简指南如何管理你的Bee节点状态数据 ?