swapper-org / NodeChain

Nodechain is a service that allows you to create nodes on a blockchain and connect to them natively through APIs. The goal is to allow the user to build their own nodes natively without having to rely on external services.
MIT License
7 stars 5 forks source link

80 get transactions method #113

Closed 0xp3gasus closed 2 years ago

0xp3gasus commented 2 years ago

Description

New RPC method getTransactions over getTransactionMethod

Fixes #80 (issue)

Dependencies (if any)

Type of change

How Has This Been Tested?

curl --location --request POST 'http://localhost:80/btc/regtest/rpc' \
--header 'Content-Type: application/json' \
--data-raw '{
    "id": 1609070896412,
    "method": "getTransactions",
    "params": {
        "txHashes": [
            "06a839ad325562a2785367ff270ae2d2c30576ffdea56c99c3218edfb791c941",
            "dd8d396fcaa88f04e131bf90c82363062b05cfc18c91238c24ae03fbd9a31cff"
        ]
    },
    "jsonrpc": "2.0"
}'
{
    "id": 1609070896412,
    "jsonrpc": "2.0",
    "result": {
        "transactions": [
            {
                "transaction": {
                    "txId": "06a839ad325562a2785367ff270ae2d2c30576ffdea56c99c3218edfb791c941",
                    "txHash": "6b89dfe1402c711e7ecb54973c9c3d6d28fee9321976607e629d52e5b102f7fc",
                    "blockNumber": "1223",
                    "fee": "705",
                    "inputs": [
                        {
                            "amount": "78125000",
                            "address": "bcrt1qtylthjgpnk03w3j7ypse9mz0sg07uutcpz0ssz"
                        },
                        {
                            "amount": "0",
                            "address": null
                        }
                    ],
                    "outputs": [
                        {
                            "amount": "295",
                            "address": "bcrt1qlfdnrzmg9y52t474xyexc2vep8hkdp7jg02mj0"
                        },
                        {
                            "amount": "78124000",
                            "address": "bcrt1qj4svfwrxxsjxzfvtsvmzzd0vvglc8r09q0csrg"
                        }
                    ],
                    "data": {
                        "txid": "06a839ad325562a2785367ff270ae2d2c30576ffdea56c99c3218edfb791c941",
                        "hash": "6b89dfe1402c711e7ecb54973c9c3d6d28fee9321976607e629d52e5b102f7fc",
                        "version": 2,
                        "size": 222,
                        "vsize": 141,
                        "weight": 561,
                        "locktime": 0,
                        "vin": [
                            {
                                "txid": "7e1879cc8f7f6ff6571be46ce1c1b2ba3fcdfdaa32dd0de50d0add86fd840904",
                                "vout": 0,
                                "scriptSig": {
                                    "asm": "",
                                    "hex": ""
                                },
                                "txinwitness": [
                                    "304402201c97da21c54d752567d828838b887e2072fe3d3a1652284d02dc35e634b534e4022009a114945c80bf3b1b4fe1b70e80a23da717d202e2bb1a0cc6ec050c39adb5ba01",
                                    "03b27695cfbe671b7495a35d0ab06f145a4caa774222bd8bbaf28829aabd2f5e14"
                                ],
                                "sequence": 4294967293
                            }
                        ],
                        "vout": [
                            {
                                "value": 2.95e-06,
                                "n": 0,
                                "scriptPubKey": {
                                    "asm": "0 fa5b318b682928a5d7d531326c299909ef6687d2",
                                    "hex": "0014fa5b318b682928a5d7d531326c299909ef6687d2",
                                    "reqSigs": 1,
                                    "type": "witness_v0_keyhash",
                                    "addresses": [
                                        "bcrt1qlfdnrzmg9y52t474xyexc2vep8hkdp7jg02mj0"
                                    ]
                                }
                            },
                            {
                                "value": 0.78124,
                                "n": 1,
                                "scriptPubKey": {
                                    "asm": "0 9560c4b866342461258b83362135ec623f838de5",
                                    "hex": "00149560c4b866342461258b83362135ec623f838de5",
                                    "reqSigs": 1,
                                    "type": "witness_v0_keyhash",
                                    "addresses": [
                                        "bcrt1qj4svfwrxxsjxzfvtsvmzzd0vvglc8r09q0csrg"
                                    ]
                                }
                            }
                        ],
                        "hex": "02000000000101040984fd86dd0a0de50ddd32aafdcd3fbab2c1e16ce41b57f66f7f8fcc79187e0000000000fdffffff022701000000000000160014fa5b318b682928a5d7d531326c299909ef6687d2e013a804000000001600149560c4b866342461258b83362135ec623f838de50247304402201c97da21c54d752567d828838b887e2072fe3d3a1652284d02dc35e634b534e4022009a114945c80bf3b1b4fe1b70e80a23da717d202e2bb1a0cc6ec050c39adb5ba012103b27695cfbe671b7495a35d0ab06f145a4caa774222bd8bbaf28829aabd2f5e1400000000",
                        "blockhash": "2d17efcb49b81c4956dcd6e6ed1f1623ee822f349556150945f06aae9434e8d4",
                        "confirmations": 2,
                        "time": 1646591571,
                        "blocktime": 1646591571
                    }
                }
            },
            {
                "transaction": {
                    "txId": "dd8d396fcaa88f04e131bf90c82363062b05cfc18c91238c24ae03fbd9a31cff",
                    "txHash": "eb654ea62835954c551bdd9949dd4f12723b7f8b932b2b7ad59ea3dc372ebc9c",
                    "blockNumber": "1222",
                    "fee": "705",
                    "inputs": [
                        {
                            "amount": "78125000",
                            "address": "bcrt1qtylthjgpnk03w3j7ypse9mz0sg07uutcpz0ssz"
                        },
                        {
                            "amount": "0",
                            "address": null
                        }
                    ],
                    "outputs": [
                        {
                            "amount": "295",
                            "address": "bcrt1qlfdnrzmg9y52t474xyexc2vep8hkdp7jg02mj0"
                        },
                        {
                            "amount": "78124000",
                            "address": "bcrt1qj4svfwrxxsjxzfvtsvmzzd0vvglc8r09q0csrg"
                        }
                    ],
                    "data": {
                        "txid": "dd8d396fcaa88f04e131bf90c82363062b05cfc18c91238c24ae03fbd9a31cff",
                        "hash": "eb654ea62835954c551bdd9949dd4f12723b7f8b932b2b7ad59ea3dc372ebc9c",
                        "version": 2,
                        "size": 222,
                        "vsize": 141,
                        "weight": 561,
                        "locktime": 0,
                        "vin": [
                            {
                                "txid": "bf2fcb54241609b5e5cbdf7a908f3c01dff1df16897e5b0de9aa906019203801",
                                "vout": 0,
                                "scriptSig": {
                                    "asm": "",
                                    "hex": ""
                                },
                                "txinwitness": [
                                    "3044022067df87ba791554133c7e30a272636138beedcf3a82ae7f062b261c9f7b4462e0022077c43104e901729f035082ebcfb47fe2483ae8289a0f18f656da4b4fda979a4301",
                                    "03b27695cfbe671b7495a35d0ab06f145a4caa774222bd8bbaf28829aabd2f5e14"
                                ],
                                "sequence": 4294967293
                            }
                        ],
                        "vout": [
                            {
                                "value": 2.95e-06,
                                "n": 0,
                                "scriptPubKey": {
                                    "asm": "0 fa5b318b682928a5d7d531326c299909ef6687d2",
                                    "hex": "0014fa5b318b682928a5d7d531326c299909ef6687d2",
                                    "reqSigs": 1,
                                    "type": "witness_v0_keyhash",
                                    "addresses": [
                                        "bcrt1qlfdnrzmg9y52t474xyexc2vep8hkdp7jg02mj0"
                                    ]
                                }
                            },
                            {
                                "value": 0.78124,
                                "n": 1,
                                "scriptPubKey": {
                                    "asm": "0 9560c4b866342461258b83362135ec623f838de5",
                                    "hex": "00149560c4b866342461258b83362135ec623f838de5",
                                    "reqSigs": 1,
                                    "type": "witness_v0_keyhash",
                                    "addresses": [
                                        "bcrt1qj4svfwrxxsjxzfvtsvmzzd0vvglc8r09q0csrg"
                                    ]
                                }
                            }
                        ],
                        "hex": "02000000000101013820196090aae90d5b7e8916dff1df013c8f907adfcbe5b509162454cb2fbf0000000000fdffffff022701000000000000160014fa5b318b682928a5d7d531326c299909ef6687d2e013a804000000001600149560c4b866342461258b83362135ec623f838de502473044022067df87ba791554133c7e30a272636138beedcf3a82ae7f062b261c9f7b4462e0022077c43104e901729f035082ebcfb47fe2483ae8289a0f18f656da4b4fda979a43012103b27695cfbe671b7495a35d0ab06f145a4caa774222bd8bbaf28829aabd2f5e1400000000",
                        "blockhash": "4a9ae5ab91aa69c7c92c960bb689ff038549767bcd9e782bee11eeaee544162f",
                        "confirmations": 3,
                        "time": 1646591571,
                        "blocktime": 1646591571
                    }
                }
            }
        ]
    }
}

Test Configuration:

Related PR or Docs PR

Docs PR related # Other PR related #

Good practices to consider