docker部署LTC v0.18.1版本开发网

LTC镜像生成

一、LTC镜像生成

  • 1.下载基础镜像
docker pull buildpack-deps:jessie-curl
  • 2.编写Dockerfile
# vim Dockerfile 

FROM buildpack-deps:jessie-curl
RUN wget -O litecoin.tar.gz https://download.litecoin.org/litecoin-0.18.1/linux/litecoin-0.18.1-x86_64-linux-gnu.tar.gz \
        && tar -xzvf litecoin.tar.gz \
        && cd litecoin-0.18.1/bin \
        && mv litecoin-cli litecoin-qt litecoin-tx litecoind litecoin-wallet /usr/local/bin \
        && apt-get update \
        && apt-get install net-tools \
        && cd / \
        && rm -Rfv *litecoin*
EXPOSE 9332 9333 19332 19335 19443  19444
WORKDIR /root/.litecoin
ENTRYPOINT ["litecoind"]

注:EXPOSE用来指定端口,使容器内的应用可以通过端口和外界交互。rpc远程调用协议的端口:(9332, testnet:19332, regtest: 19443);其他节点同步端口:(main: 9333, testnet: 19335,regtest: 19444)。

  • 3.构建镜像
docker build . -t ltc/litecoin:v0.18.1
  • 4.查看镜像
# docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
ltc/litecoin             v0.18.1             344a75a75559        20 seconds ago      245MB

注:以上为个人根据版本更新情况构建LTC镜像,也可以使用官方的bsv镜像:https://hub.docker.com/r/uphold/litecoin-core

二、LTC容器生成

  • 1.创建ltc数据目录
mkdir -p /opt/docker/ltc-regtest/data
  • 2.启动ltc开发网容器
docker run -itd --restart=unless-stopped -v /etc/localtime:/etc/localtime -v /etc/timezone:/etc/timezone --name ltc-regtest -v /opt/docker/ltc-regtest/data:/root/.litecoin/regtest -p 19443:19443 -p 19444:19444 ltc/litecoin:v0.18.1 -regtest=1 -server=1 -rpcuser=admin -rpcpassword=123456 -txindex=1 -paytxfee=0.00005 -rpcport=19443 -rpcallowip=0.0.0.0/0 -port=19444 -rpcbind=0.0.0.0:19443

参数解释

默认启动为主网,不同网络之间的区别在于创世区块不同,如果部署测试网,参数应为:-testnet=1,如果部署开发网,可以使用参数:-regtest=1:表示启动的是 regtest 网络;或者-chain=regtest指定需要使用的网络,

-txindex=1: 表示对所有的交易进行索引;否则默认只对与钱包地址有关的交易索引(使 getrawtransaction rpc 可调用完整的事务索引)

-server=1:表示接受命令行和JSON-RPC命令

-paytxfee=0.00005:手续费率指定,此参数表示:0.00005 LTC/kB

-rpcuser=admin:JSON-RPC连接的用户名

-rpcpassword=123456:JSON-RPC连接的密码

-rpcport=19443:JSON-RPC连接的端口(默认default(main): 9332, testnet:19332, regtest: 19443)

-rpcallowip=0.0.0.0/0:允许来自指定源的JSON-RPC连接,可指定单个IP或一个网段,此选项可以指定多次

-rpcbind=0.0.0.0:19443:绑定到给定的地址来监听JSON-RPC连接

-port=19444:p2p监听连接的端口,用于区块链节点间的通信(default(main): 9333, testnet: 19335,regtest: 19444)

三、查看bsv服务是否部署成功

  • 1.查看容器是否成功启动
# docker ps
CONTAINER ID        IMAGE                           COMMAND                  CREATED             STATUS              PORTS                                                                       NAMES
0a2a17a57d06        ltc/litecoin:0.18.1             "litecoind -regtest=…"   2 minutes ago       Up 2 minutes        9332-9333/tcp, 19332/tcp, 19335/tcp, 0.0.0.0:19443-19444->19443-19444/tcp   ltc-regtest
  • 2.查看服务启动日志是否正常
# tail -f debug.log
2021-08-10T12:00:12Z 
2021-08-10T12:00:12Z Litecoin Core version v0.18.1 (release build)
2021-08-10T12:00:12Z Validating signatures for all blocks.
2021-08-10T12:00:12Z Setting nMinimumChainWork=0000000000000000000000000000000000000000000000000000000000000000
......
2020-12-30T07:23:53Z Opened LevelDB successfully
2020-12-30T07:23:53Z Using obfuscation key for /root/.litecoin/regtest/blocks/index: 0000000000000000
2020-12-30T07:23:53Z LoadBlockIndexDB: last block file = 0
2020-12-30T07:23:53Z LoadBlockIndexDB: last block file info: CBlockFileInfo(blocks=0, size=0, heights=0...0, time=1970-01-01...1970-01-01)
2020-12-30T07:23:53Z Checking all blk files are present...
......
2021-08-10T12:00:13Z UpdateTip: new best=530827f38f93b43ed12af0b3ad25a288dc02ed74d6d7857862df51fc56c416f9 height=0 version=0x00000001 log2_work=1 tx=1 date='2011-02-02T23:16:42Z' progress=1.000000 cache=0.0MiB(0txo)
......
2021-08-10T12:00:13Z dnsseed thread exit
2021-08-10T12:00:13Z opencon thread start
2021-08-10T12:01:14Z Adding fixed seed nodes as DNS doesn't seem to be available.

四、常用接口使用

  • 创建地址 getnewaddress
# curl --user admin:123456 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getnewaddress", "params": ["test2"] }' -H 'content-type: text/plain;' http://127.0.0.1:19443
{"result":"QYa78xSfwmwbK7r8fqDfXuPNei3qAdkMyG","error":null,"id":"curltest"}
  • 出块 generatetoaddress

注:LTC节点101块时产生出块收益

# curl --user admin:123456 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "generatetoaddress", "params": [6,"QYa78xSfwmwbK7r8fqDfXuPNei3qAdkMyG"] }' -H 'content-type: text/plain;' http://127.0.0.1:19443
{"result":["40e2560bbb2f6734b689d3ee787a0e384670110f5f1f7649ee8908a2dc735cc3","54bc2c3a61e41beebd5557e75fc27da01431d1104e4cb3df8f8343ad6a863dab","ab0aed03ed82f2f1af05a27ee6a45a414318020822b6e7ab9d6eacc56c2ae902","23a7a63f1e7ca48d2ee6a0b51245aab0b6da702c4e7535b55cc88d9a58302da5","c51ca0837c4a172716c2a3e491df3cf4aaa50369f92b467f062515052621a945","1cc7b5cb64000934d9a4705cf0922ca2c847c3f51bfa80ad459298fbd50f1861"],"error":null,"id":"curltest"}
  • 获取最新区块高度 getblockcount
# curl --user admin:123456 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblockcount", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:19443
{"result":101,"error":null,"id":"curltest"}
  • 显示bch钱包中所有地址余额 listaddressgroupings
# curl --user admin:123456 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "listaddressgroupings", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:19443
{"result":[[["QYa78xSfwmwbK7r8fqDfXuPNei3qAdkMyG",50.00000000,"test2"]]],"error":null,"id":"curltest"}
  • 发送金额至指定地址 sendtoaddress
# curl --user admin:123456 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "sendtoaddress", "params": ["Qg3o1dH1NhG47rYboni3ZxwLsGnSNn7eyY",11] }' -H 'content-type: text/plain;' http://127.0.0.1:19443
{"result":"d674d7bbc1bb7c7562b34f2cb66263dfbf84abe5e6bdafc1aabf7b393e671ed9","error":null,"id":"curltest"}
  • 查询未花费输出 listunspent
# curl --user admin:123456 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "listunspent", "params": [1, 9999999, ["QYa78xSfwmwbK7r8fqDfXuPNei3qAdkMyG"]] }' -H 'content-type: text/plain;' http://127.0.0.1:19443
{"result":[{"txid":"c38e8746213d1946149aca1d9dc0dc33bcefd86955f2ca1533047da4a8ba9eb4","vout":0,"address":"QYa78xSfwmwbK7r8fqDfXuPNei3qAdkMyG","label":"test2","redeemScript":"0014589e7111fafe6d92225fc39273fc01a4acbc4ebb","scriptPubKey":"a91483468b6e080369225ec72c92e51a5bbfbd913be487","amount":50.00000000,"confirmations":102,"spendable":true,"solvable":true,"desc":"sh(wpkh([bb2327d0/0'/0'/0']037208c027b4e4945b01360d738572608f1ee269de3cc02f94bc886fcebdbaaa51))#q6avw075","safe":true},{"txid":"aaae37410a1f4c4cfb456606bb7fab7e42383f0d42fb5b9e1ad047cedafa5cd7","vout":0,"address":"QYa78xSfwmwbK7r8fqDfXuPNei3qAdkMyG","label":"test2","redeemScript":"0014589e7111fafe6d92225fc39273fc01a4acbc4ebb","scriptPubKey":"a91483468b6e080369225ec72c92e51a5bbfbd913be487","amount":50.00000000,"confirmations":101,"spendable":true,"solvable":true,"desc":"sh(wpkh([bb2327d0/0'/0'/0']037208c027b4e4945b01360d738572608f1ee269de3cc02f94bc886fcebdbaaa51))#q6avw075","safe":true}],"error":null,"id":"curltest"}
点赞 0
收藏 0
分享
本文参与登链社区写作激励计划 ,好文好收益,欢迎正在阅读的你也加入。

0 条评论

请先 登录 后评论
杰哥的技术杂货铺
杰哥的技术杂货铺
0x6e60...2aa2
六年区块链开发及运维经验,成都电子科技大学Web3讲师,利用该平台进行技术分享,可私信进行交流沟通