caivega / ipfslib

Other
2 stars 1 forks source link

[enhancement] - 关于getTransaction方法的返回结果中,meta等信息可选是否需要返回的提议 #178

Closed foreso-GitHub closed 3 years ago

foreso-GitHub commented 3 years ago

getTransaction的几个方法【包括jt_getTransactionByHash,jt_getTransactionByIndex,jt_getTransactionByBlockHashAndIndex和jt_getTransactionByBlockNumberAndIndex】,目前返回的tx信息如下。

{
    "id": 1,
    "jsonrpc": "2.0",
    "result": [
        {
            "result": {
                "TransactionType": "Payment",
                "Flags": 0,
                "Account": "js6jbGAnFiXFokBR4ZzvAMEPAptk52uahi",
                "Sequence": 622,
                "Fee": "10",
                "SigningPubKey": "027E24B8AD8DA3C29B0B6C6DBFB21A9A774A0351BE6C83F44C097493E9C2021B2A",
                "TxnSignature": "304402200478C1D954CED79614CBE8781F24AC27BB1281E7A6F2A0F290B4B9BA2CA27AC302203CF7E868F9FD764302AF1C74434778E97CE876DAD059553ED02EB5447FF6B907",
                "Memos": [
                    {
                        "Memo": {
                            "MemoType": "",
                            "MemoData": "6175746F746573743A207472616E736665722074657374",
                            "MemoFormat": ""
                        }
                    }
                ],
                "hash": "CA0FB644CF5530929EE1A088B22657D65CB98954DB287387FB09773863B69DB6",
                "Destination": "jn92fYxDDr59myNjBGj2AKzPN9FZJPtaGk",
                "Amount": {
                    "value": "15",
                    "currency": "SWT",
                    "issuer": "jjjjjjjjjjjjjjjjjjjjjhoLvTp"
                },
                "date": 665552835,
                "inLedger": 103671,
                "ledger_index": 103671,
                "meta": {
                    "AffectedNodes": [
                        {
                            "ModifiedNode": {
                                "FinalFields": {
                                    "Hash": "0000000000000000000000000000000000000000000000000000000000000000",
                                    "Account": "jhCVwTcg5aYWMMdfDmwqYxBr5NMA1PDfyg",
                                    "Sequence": 0,
                                    "Balance": {
                                        "value": "4605690",
                                        "currency": "SWT",
                                        "issuer": "jjjjjjjjjjjjjjjjjjjjjhoLvTp"
                                    }
                                },
                                "LedgerEntryType": "AccountRoot",
                                "PreviousFields": {
                                    "Hash": "0000000000000000000000000000000000000000000000000000000000000000",
                                    "Account": "jhCVwTcg5aYWMMdfDmwqYxBr5NMA1PDfyg",
                                    "Sequence": 0,
                                    "Balance": {
                                        "value": "4605680",
                                        "currency": "SWT",
                                        "issuer": "jjjjjjjjjjjjjjjjjjjjjhoLvTp"
                                    }
                                }
                            }
                        },
                        {
                            "ModifiedNode": {
                                "FinalFields": {
                                    "Hash": "0000000000000000000000000000000000000000000000000000000000000000",
                                    "Account": "js6jbGAnFiXFokBR4ZzvAMEPAptk52uahi",
                                    "Sequence": 622,
                                    "Balance": {
                                        "value": "10029985088",
                                        "currency": "SWT",
                                        "issuer": "jjjjjjjjjjjjjjjjjjjjjhoLvTp"
                                    }
                                },
                                "LedgerEntryType": "AccountRoot",
                                "PreviousFields": {
                                    "Hash": "0000000000000000000000000000000000000000000000000000000000000000",
                                    "Account": "js6jbGAnFiXFokBR4ZzvAMEPAptk52uahi",
                                    "Sequence": 621,
                                    "Balance": {
                                        "value": "10029985113",
                                        "currency": "SWT",
                                        "issuer": "jjjjjjjjjjjjjjjjjjjjjhoLvTp"
                                    }
                                }
                            }
                        },
                        {
                            "ModifiedNode": {
                                "FinalFields": {
                                    "Hash": "0000000000000000000000000000000000000000000000000000000000000000",
                                    "Account": "jn92fYxDDr59myNjBGj2AKzPN9FZJPtaGk",
                                    "Sequence": 0,
                                    "Balance": {
                                        "value": "171008652",
                                        "currency": "SWT",
                                        "issuer": "jjjjjjjjjjjjjjjjjjjjjhoLvTp"
                                    }
                                },
                                "LedgerEntryType": "AccountRoot",
                                "PreviousFields": {
                                    "Hash": "0000000000000000000000000000000000000000000000000000000000000000",
                                    "Account": "jn92fYxDDr59myNjBGj2AKzPN9FZJPtaGk",
                                    "Sequence": 0,
                                    "Balance": {
                                        "value": "171008637",
                                        "currency": "SWT",
                                        "issuer": "jjjjjjjjjjjjjjjjjjjjjhoLvTp"
                                    }
                                }
                            }
                        }
                    ],
                    "TransactionIndex": 42,
                    "TransactionResult": "tesSUCCESS"
                }
            }
        }
    ]
}

可以看到,其中meta信息占了很大的部分,可能接近整个信息的2/3。其实app开发的用户在大多数时候并不关心meta信息,因此建议增加一个参数showMeta,让用户自己决定这次tx返回信息是否要包括meta,这样应该能很大程度地节约这个方法调用消耗的带宽。该参数默认值可以是不返回。

caivega commented 3 years ago

现在有一个jt_getTransactionReceipt会返回meta信息,如果这个地方大家觉得不需要,我们就去掉,再看看东东的意见

caivega commented 3 years ago

或者加一个full参数(现在这个参数,在查block的时候用过),默认为false, 为true时会返回包括meta的信息

foreso-GitHub commented 3 years ago

现在有一个jt_getTransactionReceipt会返回meta信息,如果这个地方大家觉得不需要,我们就去掉,再看看东东的意见

原来jt_getTransactionReceipt返回的就是meta信息啊。这样的话我建议把meta信息直接从tx中删除。如果用户需要,就通过jt_getTransactionReceipt查询。

foreso-GitHub commented 3 years ago

功能完备的前提下,我们尽量做得简单。

caivega commented 3 years ago

个人倾向像jt_getBlockByNumber及jt_getBlockByHash那样,使用一个full的参数,full参数默认为false, 为true的时候,返回更详细的交易信息,在getTransaction方法里边,就是显示更详细的交易及meta信息

caivega commented 3 years ago

另外,除了transaction本身的信息,以及meta信息,还有date": 665552835,"inLedger": 103671,"ledger_index": 103671, 主要是ledger_index信息,因这个信息,是在打包的时候填的,不能算到hash里边去,所以,这个信息,如果没有full的标志的话, 是没办法返回的

foreso-GitHub commented 3 years ago

个人倾向像jt_getBlockByNumber及jt_getBlockByHash那样,使用一个full的参数,full参数默认为false, 为true的时候,返回更详细的交易信息,在getTransaction方法里边,就是显示更详细的交易及meta信息

另外,除了transaction本身的信息,以及meta信息,还有date": 665552835,"inLedger": 103671,"ledger_index": 103671, 主要是ledger_index信息,因这个信息,是在打包的时候填的,不能算到hash里边去,所以,这个信息,如果没有full的标志的话, 是没办法返回的

同意。

foreso-GitHub commented 3 years ago

@zyd82 东东,需要增加一下TestCase

foreso-GitHub commented 3 years ago

试用了一下新版本,发现date": 665552835,"inLedger": 103671,"ledger_index": 103671这3个信息很常用,在不少地方都要用到。能否做到full=true时还是包含这3个信息,而不包含meta?加上full参数的主要目的还是meta在大部分场合没有意义,因此节约带宽。这3个信息占用的size很小,最好还是能返回。

caivega commented 3 years ago

试用了一下新版本,发现date": 665552835,"inLedger": 103671,"ledger_index": 103671这3个信息很常用,在不少地方都要用到。能否做到full=true时还是包含这3个信息,而不包含meta?加上full参数的主要目的还是meta在大部分场合没有意义,因此节约带宽。这3个信息占用的size很小,最好还是能返回。

done, 下一个build验证下

foreso-GitHub commented 3 years ago

在版本v0.5.4-dev-20210204-d083a50b96df7ad31ddd275f80e260016e992ce4中验证,已经更新。