stratisproject / StratisBitcoinFullNode

Bitcoin full node in C#
https://stratisplatform.com
MIT License
787 stars 312 forks source link

call getrawtransaction RPC with null reply #2731

Closed xiewenlong1202 closed 6 years ago

xiewenlong1202 commented 6 years ago

As I know, Stratis is a C# implementation of Bitcoind, I trying to use the same RPC call of BTC to act with Stratis. But after try it, I got some problem with it.

  1. I try to call the getrawtransaction RPC method and it return with 204 status code and nothing about the transaction after that I try to use the Swagger API /api/BlockStore/block to get transaction details, also set ShowTransactionDetails to be true this time I got transaction information but, the field is different from a BTC transaction In the vouts, I Can't find the address field

I want to know, how to get transactions infos in a block in Stratis blockchain.

zeptin commented 6 years ago

@xiewenlong1202 Are you running the daemon with -txindex=1?

zeptin commented 6 years ago

I've looked at the model we use to create the JSON, and it should have an addresses array in the Vout, if it is able to properly determine one for the type of transaction it is. Can you paste the output you are getting here?

xiewenlong1202 commented 6 years ago

thanks for reply, I did not run the daemon with -txindex=1 argument the command I used to start Stratis Node is as follows: dotnet run -testnet -server=1 -rpcuser=oneroot -rpcpassword=oneroot123

the request to Swagger UI is as follows: curl -X GET "http://localhost:38221/api/BlockStore/block?Hash=0d4971ab7f86b507e7a296c5e19c3d65e3c98864a8cb9f9be54129463432a95e&ShowTransactionDetails=true&OutputJson=true" -H "accept: application/json"

the reply I got is as follow: { "transactions": [ { "hex": "01000000506ee65b010000000000000000000000000000000000000000000000000000000000000000ffffffff050340b50900ffffffff0100000000000000000000000000", "txid": "4f5b305dbe09d755b7efa167613b1f52ddf87a2e62d73f74bd94a722ba956f22", "size": 69, "version": 1, "locktime": 0, "vin": [ { "coinbase": "0340b50900", "sequence": 4294967295 } ], "vout": [ { "value": 0, "n": 0, "scriptPubKey": { "asm": "", "hex": "", "type": "nonstandard" } } ] }, { "hex": "01000000506ee65b0135c59cb8bf34d98590efe61fc94290c07a8b048b893199b71f7ee7b9aa6422200100000049483045022100b28977b2e530fd2466b6cc4b35276ae158a1e9975c862c8a6e9af9b2db292b0902201b5ddcf93944d23a45ec50ec4410d228ef331d00a4c3602bf0e95f49279c383a01ffffffff020000000000000000001c339aeb70000000232102a961c743372b3b79e4c6a1c2917fecbcf351158e4b01fde729bb70f308cd34f4ac00000000", "txid": "10ebe9c14f0a2bacfd361642597b6ab359db7224c61ecb61e239539a583725ab", "size": 181, "version": 1, "locktime": 0, "vin": [ { "txid": "202264aab9e77e1fb79931898b048b7ac09042c91fe6ef9085d934bfb89cc535", "vout": 1, "scriptSig": { "asm": "3045022100b28977b2e530fd2466b6cc4b35276ae158a1e9975c862c8a6e9af9b2db292b0902201b5ddcf93944d23a45ec50ec4410d228ef331d00a4c3602bf0e95f49279c383a01", "hex": "483045022100b28977b2e530fd2466b6cc4b35276ae158a1e9975c862c8a6e9af9b2db292b0902201b5ddcf93944d23a45ec50ec4410d228ef331d00a4c3602bf0e95f49279c383a01" }, "sequence": 4294967295 } ], "vout": [ { "value": 0, "n": 0, "scriptPubKey": { "asm": "", "hex": "", "type": "nonstandard" } }, { "value": 4849.8908854, "n": 1, "scriptPubKey": { "asm": "02a961c743372b3b79e4c6a1c2917fecbcf351158e4b01fde729bb70f308cd34f4 OP_CHECKSIG", "hex": "2102a961c743372b3b79e4c6a1c2917fecbcf351158e4b01fde729bb70f308cd34f4ac", "type": "pubkey" } } ] } ], "tx": [ "4f5b305dbe09d755b7efa167613b1f52ddf87a2e62d73f74bd94a722ba956f22", "10ebe9c14f0a2bacfd361642597b6ab359db7224c61ecb61e239539a583725ab" ], "hash": "0d4971ab7f86b507e7a296c5e19c3d65e3c98864a8cb9f9be54129463432a95e", "size": 403, "version": 536870912, "bits": "1a32903b", "time": "1541828176", "difficulty": 331800.47051609325, "merkleroot": "b6b43a719625149e3310f062bdd9f2fd61c48b3aba3a7214f15ebe1ed85828c9", "previousblockhash": "bb4ef6a1fc079bf74080b0660f5b55e2970cb06c12991d3bd41d76b802b58fb1", "nonce": 0, "height": 636224 }

xiewenlong1202 commented 6 years ago

the following is the raw transaction of the same transaction I got from the testnet explorer

{ "txid": "10ebe9c14f0a2bacfd361642597b6ab359db7224c61ecb61e239539a583725ab", "version": 1, "time": 1541828176, "locktime": 0, "vin": [ { "txid": "202264aab9e77e1fb79931898b048b7ac09042c91fe6ef9085d934bfb89cc535", "vout": 1, "scriptSig": { "asm": "3045022100b28977b2e530fd2466b6cc4b35276ae158a1e9975c862c8a6e9af9b2db292b0902201b5ddcf93944d23a45ec50ec4410d228ef331d00a4c3602bf0e95f49279c383a01", "hex": "483045022100b28977b2e530fd2466b6cc4b35276ae158a1e9975c862c8a6e9af9b2db292b0902201b5ddcf93944d23a45ec50ec4410d228ef331d00a4c3602bf0e95f49279c383a01" }, "sequence": 4294967295 } ], "vout": [ { "value": 0, "n": 0, "scriptPubKey": { "asm": "", "hex": "", "type": "nonstandard" } }, { "value": 4849.8908854, "n": 1, "scriptPubKey": { "asm": "02a961c743372b3b79e4c6a1c2917fecbcf351158e4b01fde729bb70f308cd34f4 OP_CHECKSIG", "hex": "2102a961c743372b3b79e4c6a1c2917fecbcf351158e4b01fde729bb70f308cd34f4ac", "reqSigs": 1, "type": "pubkey", "addresses": [ "TPcVgKfg2wHgABG3U5Rim7hKfk8mQPDWAH" ] } } ], "blockhash": "0d4971ab7f86b507e7a296c5e19c3d65e3c98864a8cb9f9be54129463432a95e", "confirmations": 6, "blocktime": 1541828176 }

there is address field in the vouts list

xiewenlong1202 commented 6 years ago

the status information of the node is as following: { "agent": "StratisBitcoin", "version": "1.2.3.0", "network": "StratisTest", "coinTicker": "TSTRAT", "processId": 34140, "consensusHeight": 636231, "blockStoreHeight": 636231, "inboundPeers": [], "outboundPeers": [ { "version": "/Stratis:2.0.0.4/", "remoteSocketEndpoint": "[::ffff:40.113.118.138]:26178", "tipHeight": 636231 }, { "version": "StratisBitcoin:1.2.3", "remoteSocketEndpoint": "[::ffff:104.43.245.241]:26178", "tipHeight": 636229 }, { "version": "StratisBitcoin:1.2.3", "remoteSocketEndpoint": "[::ffff:52.173.30.95]:26178", "tipHeight": 636230 }, { "version": "StratisBitcoin:1.2.3", "remoteSocketEndpoint": "[::ffff:52.176.62.44]:26178", "tipHeight": 636231 }, { "version": "jb3-StratisBitcoin:1.2.3", "remoteSocketEndpoint": "[::ffff:13.70.81.5]:26178", "tipHeight": 636230 }, { "version": "StratisBitcoin:1.2.3", "remoteSocketEndpoint": "[::ffff:191.235.85.131]:26178", "tipHeight": 636230 }, { "version": "/Stratis:2.0.0.5/", "remoteSocketEndpoint": "[::ffff:54.37.46.84]:26178", "tipHeight": 636231 }, { "version": "StratisBitcoin:1.2.3", "remoteSocketEndpoint": "[::ffff:51.141.83.38]:26178", "tipHeight": 636231 } ], "enabledFeatures": [ "Stratis.Bitcoin.Base.BaseFeature", "Stratis.Bitcoin.Features.BlockStore.BlockStoreFeature", "Stratis.Bitcoin.Features.Consensus.PosConsensusFeature", "Stratis.Bitcoin.Features.MemoryPool.MempoolFeature", "Stratis.Bitcoin.Features.ColdStaking.ColdStakingFeature", "Stratis.Bitcoin.Features.Miner.MiningFeature", "Stratis.Bitcoin.Features.Api.ApiFeature", "Stratis.Bitcoin.Features.Apps.AppsFeature", "Stratis.Bitcoin.Features.RPC.RPCFeature" ], "dataDirectoryPath": "/Users/xie/.stratisnode/stratis/StratisTest", "runningTime": "02:40:38.8744120", "difficulty": 344925.60580982635, "protocolVersion": 70000, "testnet": true, "relayFee": 0.0001 }

did my node version too old? I pull from the git just 2 days ago

xiewenlong1202 commented 6 years ago

I restart the Stratis Node with adding the -txindex=1 and -reindex(if don't add will got error), after that, the getrawtransation RPC still got null and 204 status code and the /api/BlockStore/block still has no address field in the vouts

dangershony commented 6 years ago

These is latest version so maybe there is a bug we will investigate.

So you confirm that including the -txindex you still dont get a 204?

mikedennis commented 6 years ago

There is a working RPC test for getrawtransaction, take a look at RPCTestsMutable.TestRpcSendToAddressIsSuccessful() it uses getrawtransaction if you want to see sample of usage.

My guess is it's throwing this error for your txid RPCErrorCode.RPC_INVALID_ADDRESS_OR_KEY which is why you are getting a 204

xiewenlong1202 commented 6 years ago

@mikedennis thanks for reply, I have checked the file you said about. and the code is:

               // Check the hash calculated correctly.
                var tx = rpcClient.GetRawTransaction(txid);
                Assert.Equal(txid, tx.GetHash());

I notice that the rpcClient is created by the "node" object which is created by a "builder" object I am not a c# programmer and can't find out what exactly this object do

I want to use the cmd tool like "curl", and got some response

mikedennis commented 6 years ago

@xiewenlong1202 Sure no worries, if you can post your exact curl command for the RPC call and we can hopefully troubleshoot it. I only see the curl for the swagger UI call in the above code.

rpcClient is a C# client in NBitcoin that makes calling RPC methods from C# easy.

xiewenlong1202 commented 6 years ago

@dangershony thanks for attention. I updated the code and start the full node with -txindex arggument, and now both getrawtransaction and decoderawtransaction works. but after decode, there is still not "address" field in the vout the following is the response: "vout": [ { "value": 0, "n": 0, "scriptPubKey": { "asm": "", "hex": "", "type": "nonstandard" } }, { "value": 2121.8769643, "n": 1, "scriptPubKey": { "asm": "026f617a9cbbddffa2bd7d47dee8875e7fcd95f9611e9022368ddadb7bc5ab83ca OP_CHECKSIG", "hex": "21026f617a9cbbddffa2bd7d47dee8875e7fcd95f9611e9022368ddadb7bc5ab83caac", "type": "pubkey" } } ]

xiewenlong1202 commented 6 years ago

@mikedennis I tried this morning, and rpc reply correct but there is no address in vout, I don't know why and I want to know if this is tool to get address from the hex string or the asm following is what I got: "vout": [ { "value": 0, "n": 0, "scriptPubKey": { "asm": "", "hex": "", "type": "nonstandard" } }, { "value": 2121.8769643, "n": 1, "scriptPubKey": { "asm": "026f617a9cbbddffa2bd7d47dee8875e7fcd95f9611e9022368ddadb7bc5ab83ca OP_CHECKSIG", "hex": "21026f617a9cbbddffa2bd7d47dee8875e7fcd95f9611e9022368ddadb7bc5ab83caac", "type": "pubkey" } } ]

xiewenlong1202 commented 6 years ago

thanks for all members' reply, now the getrawtransaction RPC works well