“bitcoind `listunspenttransactions` 报错 ‘未指定钱包文件'”

huangapple go评论65阅读模式
英文:

bitcoind `listunspenttransactions` throws "Wallet file not specified" error

问题

I am using btcd rpcClient. In a nutshell, what I am doing, is loading a wallet, listing unspent tx and then unloading the wallet.
Here is a sample code:


import (
    "github.com/btcsuite/btcd/rpcclient"
)

connCfg := &rpcclient.ConnConfig{
    Host:         "url:port",
    User:         "username",
    Pass:         "password",
    HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode
    DisableTLS:   true, // Bitcoin core does not provide TLS by default,
}

client, err := rpcclient.New(connCfg, nil)
if err != nil {
    return nil, err
}

_, _ := btcClient.LoadWallet("walletname")

_, err := btcClient.ListUnspent()

fmt.Println(err)

btcClient.UnloadWallet(&farmName)

This worked completely fine on a signet node. After that I try it on a mainnet node (seemingly with the same configuration, same node version and same method of creating the wallet) and I get the following error:
"code":-19,"message":"Wallet file not specified (must request wallet RPC through /wallet/<filename> uri-path)."

I tried reproducing the problem with curl and again, on the mainnet node, this works, but on the mainnet node, I get the same error:

curl --user user:password --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "loadwallet", "params": ["walletname"] }' -H 'content-type: text/plain;' http://url:port/

curl --user user:password --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "listunspent"}' -H 'content-type: text/plain;' http://url:port/

curl --user user:password --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "unloadwallet", "params": ["walletname"] }' -H 'content-type: text/plain;' http://url:port/

Responses I get:

{"result":{"name":"walletname","warning":""},"error":null,"id":"curltest"}

{"result":null,"error":{"code":-19,"message":"Wallet file not specified (must request wallet RPC through /wallet/<filename> uri-path)."},"id":"curltest"}

{"result":{"warning":""},"error":null,"id":"curltest"}
英文:

I am using btcd rpcClient. In a nutshell, what I am doing, is loading a wallet, listing unspent tx and then unloading the wallet.
Here is a sample code:


import (
    &quot;github.com/btcsuite/btcd/rpcclient&quot;
)

connCfg := &amp;rpcclient.ConnConfig{
    Host:         &quot;url:port&quot;,
    User:         &quot;username&quot;,
    Pass:         &quot;password&quot;,
    HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode
    DisableTLS:   true, // Bitcoin core does not provide TLS by default,
}

client, err := rpcclient.New(connCfg, nil)
if err != nil {
    return nil, err
}

_, _ := btcClient.LoadWallet(&quot;walletname&quot;)

_, err := btcClient.ListUnspent()

fmt.Println(err)

btcClient.UnloadWallet(&amp;farmName)

This worked completely fine on a signet node. After that I try it on a mainnet node (seemingly with the same configuration, same node version and same method of creating the wallet) and I get the following error:
`&quot;code&quot;:-19,&quot;message&quot;:&quot;Wallet file not specified (must request wallet RPC through /wallet/&lt;filename&gt; uri-path).&quot;

I tried reproducing tge problem with curl and again, on the signet node this works, but on mainet node, I get the same error:

curl --user user:password --data-binary &#39;{&quot;jsonrpc&quot;: &quot;1.0&quot;, &quot;id&quot;:&quot;curltest&quot;, &quot;method&quot;: &quot;loadwallet&quot;, &quot;params&quot;: [&quot;walletname&quot;] }&#39; -H &#39;content-type: text/plain;&#39; http://url:port/

curl --user user:password --data-binary &#39;{&quot;jsonrpc&quot;: &quot;1.0&quot;, &quot;id&quot;: &quot;curltest&quot;, &quot;method&quot;: &quot;listunspent&quot;}&#39; -H &#39;content-type: text/plain;&#39; http://url:port/

curl --user user:password --data-binary &#39;{&quot;jsonrpc&quot;: &quot;1.0&quot;, &quot;id&quot;:&quot;curltest&quot;, &quot;method&quot;: &quot;unloadwallet&quot;, &quot;params&quot;: [&quot;walletname&quot;] }&#39; -H &#39;content-type: text/plain;&#39; http://url:port/

Responses I get:

{&quot;result&quot;:{&quot;name&quot;:&quot;walletname&quot;,&quot;warning&quot;:&quot;&quot;},&quot;error&quot;:null,&quot;id&quot;:&quot;curltest&quot;}

{&quot;result&quot;:null,&quot;error&quot;:{&quot;code&quot;:-19,&quot;message&quot;:&quot;Wallet file not specified (must request wallet RPC through /wallet/&lt;filename&gt; uri-path).&quot;},&quot;id&quot;:&quot;curltest&quot;}

{&quot;result&quot;:{&quot;warning&quot;:&quot;&quot;},&quot;error&quot;:null,&quot;id&quot;:&quot;curltest&quot;}

答案1

得分: 1

问题在于比特币守护程序启动时默认加载了一个钱包。当我加载我想要使用的钱包时,加载的钱包计数变为2。当没有指定钱包的情况下执行RPC查询时,它们会尝试使用已加载的钱包,但仅当已加载的钱包只有一个时才会这样做。由于我加载了2个钱包,它要求我指定要使用哪一个。

在签名节点上,出于某种原因,默认钱包没有加载,这就是为什么我在那里没有遇到同样的问题的原因。

可以使用listwallets方法检查已加载的钱包。

英文:

The problem was that there was a wallet that was loading by default on the bitcoin daemon startup. When I was loading the wallet that I wanted to work with, the loaded wallet count was becoming equal to 2. When the RPC queries are done without a specified wallet, they try to use the loaded wallet, but only if the loaded wallet is only one. Since I had 2 loaded wallets, it wanted me to specify which one to use.

On the signed node, the default wallet was not loading for some reason and that is why I wasn't getting the same problem there.

One can check the loaded wallets with the listwallets method.

huangapple
  • 本文由 发表于 2023年6月12日 22:33:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76457693.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定