Bee出票测试

1.首先查各节点地址

查询地址命令curl -s localhost:31635/addresses | jq

看到你的外网IP和p2p字样的地址/ip4/194.163.147.210/tcp/31634/p2p/16Uiu2HAm3Fa3cW8PSgnmrCQA3oubxigpiqrfsf5h6GArLu5e2oBc

自行修改端口

# curl -s localhost:31635/addresses | jq
{
  "overlay": "f9f7a915d122351c86e209aa4dee822b42d5d6ec084878e19d13b66e40e72a6f",
  "underlay": [
    "/ip4/194.163.147.210/tcp/31634/p2p/16Uiu2HAm3Fa3cW8PSgnmrCQA3oubxigpiqrfsf5h6GArLu5e2oBc",
    "/ip4/127.0.0.1/tcp/31634/p2p/16Uiu2HAm3Fa3cW8PSgnmrCQA3oubxigpiqrfsf5h6GArLu5e2oBc",
    "/ip4/194.163.147.210/udp/31634/quic/p2p/16Uiu2HAm3Fa3cW8PSgnmrCQA3oubxigpiqrfsf5h6GArLu5e2oBc",
    "/ip4/127.0.0.1/udp/31634/quic/p2p/16Uiu2HAm3Fa3cW8PSgnmrCQA3oubxigpiqrfsf5h6GArLu5e2oBc",
    "/ip4/194.163.147.210/tcp/31634/p2p/16Uiu2HAm3Fa3cW8PSgnmrCQA3oubxigpiqrfsf5h6GArLu5e2oBc"
  ],
  "ethereum": "0x02af2aa115c2581449e49ba11a7f5f85c692a582",
  "publicKey": "02316ed85cea09643963343cd45a08c796741d23c927c7cbbcbde43aa76aae868f",
  "pssPublicKey": "03523d1381dd6d330a8e2005fb345c8b6a8e7ae949be637d4955edff0cd0e90430"
}
2.更改配置文件

加入一个错误的bootnode引导地址,如下,把31634写错成1634

bootnode: [/ip4/194.163.147.210/tcp/1634/p2p/16Uiu2HAm3Fa3cW8PSgnmrCQA3oubxigpiqrfsf5h6GArLu5e2oBc]
3.查询连接数

连接的节点数查询命令:curl -s localhost:31635/peers | jq

各节点此时由于缺少引导地址,查询连接数应该为空

自行修改端口

# curl -s localhost:31635/peers | jq
{
  "peers": [null]
}
4.各节点内部互连
curl -X POST localhost:31635/connect/ip4/194.163.147.210/tcp/31634/p2p/16Uiu2HAm3Fa3cW8PSgnmrCQA3oubxigpiqrfsf5h6GArLu5e2oBc

各节点互连成功后再次查询。

 curl -s localhost:31635/peers | jq
{
  "peers": [
    {
      "address": "1e29fc430e7398df8cf336a15c26809b8eba0f37cfac01d9876023ea50ba6688",
      "fullNode": true
    },
    {
      "address": "b7790a4a2563ef94916406b906389ee85c749b5efa20e3d52c2b610bf44f9ca2",
      "fullNode": true
    },
    {
      "address": "cc2ed80510341041dba957bea392b6a9b81a79e80fd92d1bf0339e151976c9ea",
      "fullNode": true
    },
    {
      "address": "fa1049034ab2dc81badef66279a7da77775d1a708e7c5108af104f1ef3505fa1",
      "fullNode": true
    }
  ]
}
5.查看当前各节点余额

查询命令:curl localhost:31635/chequebook/balance | jq

curl localhost:31635/chequebook/balance | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    75  100    75    0     0    217      0 --:--:-- --:--:-- --:--:--   218
{
  "totalBalance": "9812683999998000",
  "availableBalance": "9638446999996000"
}

如果余额较多,可以手动提现到钱包

curl -XPOST http://localhost:31635/chequebook/withdraw\?amount\=100000000 | jq

如果服务较多,就从钱包转入到合约

curl -XPOST http://localhost:31635/chequebook/deposit\?amount\=1000000000 | jq
6.购买邮票

使用:curl -s -XPOST http://localhost:31633/stamps/10000000/20,得到batchID

curl -s -XPOST http://localhost:31633/stamps/10000000/20
{"batchID":"7a9027043802134973ef15b2fa6c5958d7537c11dae763db61f540c1ae521xxx"}
7.PSS测试(此节可跳过)

先查询想PSS通讯的节点地址,取overlay前4位和pssPublicKey

curl -s localhost:21635/addresses | jq
{
  "overlay": "fa1049034ab2dc81badef66279a7da77775d1a708e7c5108af104f1ef3505fa1",
  "underlay": [
    "/ip4/194.163.147.208/tcp/21634/p2p/16Uiu2HAmFh6CYKyCGaSG3jMPun2CDWDEkzrBEGjUbkiy5CP8k8GP",
    "/ip4/127.0.0.1/tcp/21634/p2p/16Uiu2HAmFh6CYKyCGaSG3jMPun2CDWDEkzrBEGjUbkiy5CP8k8GP",
    "/ip4/194.163.147.208/udp/21634/quic/p2p/16Uiu2HAmFh6CYKyCGaSG3jMPun2CDWDEkzrBEGjUbkiy5CP8k8GP",
    "/ip4/127.0.0.1/udp/21634/quic/p2p/16Uiu2HAmFh6CYKyCGaSG3jMPun2CDWDEkzrBEGjUbkiy5CP8k8GP",
    "/ip4/194.163.147.208/tcp/21634/p2p/16Uiu2HAmFh6CYKyCGaSG3jMPun2CDWDEkzrBEGjUbkiy5CP8k8GP"
  ],
  "ethereum": "0x8453539628f2c348339aaa47b066d94a7aa1018a",
  "publicKey": "0211178894e32027eb37326517ca0333292c4e6dd61a995982d7ee794b49406acd",
  "pssPublicKey": "039a99345034c76f6b4ba57c6e5c08221e92b7504d8fd0eefd15ce43d075621a15"
}

然后使用下面命令,注意更改fa10为你的overlay前4位和?recipient=pssPublicKey的地址,修改Swarm-Postage-Batch-Id

curl \
  -XPOST "localhost:31633/pss/send/test-topic/fa10?recipient=039a99345034c76f6b4ba57c6e5c08221e92b7504d8fd0eefd15ce43d075621a15" \
  --data "Hello Swarm"  \
  -H "Swarm-Postage-Batch-Id: 7a9027043802134973ef15b2fa6c5958d7537c11dae763db61f540c1ae521xxx"

接收PSS的节点安装websocat

wget https://github.com/vi/websocat/releases/download/v1.8.0/websocat_1.8.0_newer_amd64.deb
dpkg -i websocat_1.8.0_newer_amd64.deb

监听

websocat ws://localhost:21633/pss/subscribe/test-topic

可收到Hello Swarm

8.上传图片

进入你存图片的目录,使用如下命令

curl --data-binary @test.jpg  -H "Swarm-Postage-Batch-Id: 7a9027043802134973ef15b2fa6c5958d7537c11dae763db61f540c1ae521xxx" -H "Content-Type: video/jpg" "http://localhost:31633/bzz?name=test.jpg"

会得到reference

{"reference":"fc38b5a5f73bc998c3505dbc661689d1d79c8d63ca2b789756e88d019605f743"}

URL查询

URL -> http://IP地址:31633/bzz/fc38b5a5f73bc998c3505dbc661689d1d79c8d63ca2b789756e88d019605f743
9.安装swarm-cli

centos一键安装脚本

wget http://download.swarmeth.org/swarm/centos/swarmcli.sh && chmod a+x swarmcli.sh && ./swarmcli.sh

ubuntu一键安装脚本

wget http://download.swarmeth.org/swarm/ubuntu/swarmcli.sh && chmod a+x swarmcli.sh && ./swarmcli.sh

命令行输入swarm-cli看到如下输出,证明安装成功

swarm-cli 
Swarm CLI 1.0.0 - Manage your Bee node and interact with the Swarm network via the CLI

█ Usage:

swarm-cli COMMAND [OPTIONS]

█ Available Groups:

pinning    Pin, unpin and check pinned chunks
identity   Import, export and manage keypairs, identities
feed       Upload, update and view feeds
cheque     Deposit, withdraw and manage cheques
stamp      Buy, list and show postage stamps
pss        Send, receive, or subscribe to PSS messages

配置swarm-cli的端口

cd /root/.swarm-cli/
vim config.json
{"beeApiUrl":"http://localhost:31633","beeDebugApiUrl":"http://localhost:31635","identities":{}}

Esc后输入:wq保存退出

10.使用swarm-cli上传文件

使用swarm-cli upload bee.jpg,可随意上传各格式的文件。swarm上传文件花费极低。

swarm-cli upload bee.jpg
? Please select a stamp for this action.

  Stamp ID                                                         Usage
 7a9027043802134973ef15b2fa6c5958d7537c11dae763db61f540c1ae521063 (7%)
Swarm root hash -> 76ea744925e447ee99af5dab3803c32d259d1a39be70b1e5aec78ea83f187716
 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 100% | ETA: 0s | 166/166
URL -> http://localhost:31633/bzz/76ea744925e447ee99af5dab3803c32d259d1a39be70b1e5aec78ea83f187716

提供Anaconda3下载,占用大约1G空间,可练习上传

wget https://repo.anaconda.com/archive/Anaconda3-2021.05-Windows-x86_64.exe
wget https://repo.anaconda.com/archive/Anaconda3-2021.05-Linux-x86_64.sh

例:

swarm-cli upload Anaconda3-2021.05-Windows-x86_64.exe
11.出票测试

当各节点间交互的数据超过支付阈值后,即可出票

在 Swarm 中,这些点对点余额代表节点之间的信任协议。 令牌仅在节点结算支票时才真正易手。这可以手动触发,也可以在对等方达到某个阈值时触发。

使用对等余额查询curl localhost:31635/balances | jq

curl localhost:31635/balances | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   397  100   397    0     0    820      0 --:--:-- --:--:-- --:--:--   821
{
  "balances": [
    {
      "peer": "1e29fc430e7398df8cf336a15c26809b8eba0f37cfac01d9876023ea50ba6688",
      "balance": "-2880000"
    },
    {
      "peer": "b7790a4a2563ef94916406b906389ee85c749b5efa20e3d52c2b610bf44f9ca2",
      "balance": "-3710000"
    },
    {
      "peer": "cc2ed80510341041dba957bea392b6a9b81a79e80fd92d1bf0339e151976c9ea",
      "balance": "-4110000"
    },
    {
      "peer": "fa1049034ab2dc81badef66279a7da77775d1a708e7c5108af104f1ef3505fa1",
      "balance": "0"
    }
  ]
}

可以使用结算端点查看这些。

使用curl localhost:31635/chequebook/cheque | jq查看支票

curl localhost:31635/chequebook/cheque | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   524  100   524    0     0  78963      0 --:--:-- --:--:-- --:--:-- 87333
{
  "lastcheques": [
    {
      "peer": "fa1049034ab2dc81badef66279a7da77775d1a708e7c5108af104f1ef3505fa1",
      "lastreceived": null,
      "lastsent": {
        "beneficiary": "0x8453539628F2C348339AAA47b066d94A7AA1018A",
        "chequebook": "0x7bcdaeA6E21A32666e33849B1476711C08BD1370",
        "payout": "117449000001000"
      }
    },
    {
      "peer": "f9f7a915d122351c86e209aa4dee822b42d5d6ec084878e19d13b66e40e72a6f",
      "lastreceived": {
        "beneficiary": "0x520DAc99D695F9e45836f84E3fF09c832828a71c",
        "chequebook": "0x46E1147f7a479C36249cD2963F4413c10477819D",
        "payout": "89000000001000"
      },
      "lastsent": null
    }
  ]
}
12.提取支票

我们只需将对方的peer地址发布到cashout端点。

例如peerf9f7a915d122351c86e209aa4dee822b42d5d6ec084878e19d13b66e40e72a6f

curl -XPOST http://localhost:31635/chequebook/cashout/f9f7a915d122351c86e209aa4dee822b42d5d6ec084878e19d13b66e40e72a6f

查看状态

curl http://localhost:31635/chequebook/cashout/f9f7a915d122351c86e209aa4dee822b42d5d6ec084878e19d13b66e40e72a6f | jq

也可使用区块链浏览器通过transaction查看

例如:

测试网

https://goerli.etherscan.io/tx/0x开头的transaction地址

xdai

https://blockscout.com/xdai/mainnet/tx/0x开头的transaction地址

注意点:

bee配置文件里面payment设置

payment-early:     1800000
payment-threshold: 9000000
payment-tolerance: 100000000
  • --payment-early

默认 1000000000000

BZZ 中的金额低于同行支付阈值,导致 Bee 启动结算。

  • --payment-threshold(支付阈值)

默认 10000000000000

BZZ 中您希望从同行那里获得报酬的门槛。

  • --payment-tolerance

默认 10000000000000

在 BZZ 中超出支付阈值的超额债务,您与同行断开连接。

常用查询命令

注意安装jq

  • 查看合约地址
curl -s http://localhost:31635/chequebook/address | jq .chequebookAddress
  • 查看钱包地址
curl -s localhost:31635/addresses | jq .ethereum
  • 查看节点连接数
curl -s http://localhost:31635/peers | jq '.peers | length'
  • 查看支票
curl localhost:31635/chequebook/cheque | jq
  • 查看地址
curl -s localhost:31635/addresses | jq
  • 查看对等余额
curl localhost:31635/balances | jq
  • 查看当前节点余额
curl localhost:31635/chequebook/balance | jq
  • 查看连接节点
curl -s localhost:31635/peers | jq

作者赞赏码:
点赞

Copyright © OneZos all right reserved,powered by Gitbook本书发布时间: 2021-06-30 17:28:52

results matching ""

    No results matching ""