Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve: binary encoding for wallet data #88

Merged
merged 3 commits into from
Jan 23, 2024
Merged

improve: binary encoding for wallet data #88

merged 3 commits into from
Jan 23, 2024

Conversation

wthrajat
Copy link
Collaborator

@wthrajat wthrajat commented Jan 22, 2024

Aims to fix #87
Now we are using binary encoding for writing wallet files; previously .json files were used which are human-readable out of the box.

Now we cannot read the wallet files out of the box and will have to use CBOR tools like cbor.dev and cbor.me for debugging purposes.

Example of a wallet file (out of many) before and after the PR is given below:

Before

Click to view

{"file_name":"maker16102","version":0,"network":"regtest","seedphrase":"pudding actor rib trophy festival scrap clerk gospel genuine nice issue daring","passphrase":"","external_index":0,"incoming_swapcoins":[{"my_privkey":"dd20b12421d22728734535b16f15297d6fa1a13cb7cedfe21266b4732d9b95e5","other_pubkey":"037a7bdf7cafa8fb50e463affd00ae3261cfd2f2bf167909049899a9da56ae771b","other_privkey":"92b9f4bd8ec31d29cae3bf6329bc9617fca9cb1fbeade06b66f5d58881b0dc36","contract_tx":{"version":2,"lock_time":0,"input":[{"previous_output":"ec5e40b5e2a8e0f2e47f5048651258d6487ab68bd28215e81f4cad08ba3ff508:0","script_sig":"","sequence":0,"witness":[]}],"output":[{"value":28016,"script_pubkey":"002051189e1a125e0869a192e90e6ea8810f4550a85de9d7844966b33dacc88c0b53"}]},"contract_redeemscript":"827ca914e72c34a16c087526a7b5947ccca2419c983d0846876321028b50eed70326dc30f9413e555774ab0bc891810204e2f6fba5bce56a74c7504601205167210346d74d4b513d786d9aacff8c9b944dcde0e287a621ac9a8a1defc0333a1c5a5200016068b2757b88ac","hashlock_privkey":"8fe73d015cb01fc2a78349a6b44fd4908790aad975851e40f38e6ffde4b623ba","funding_amount":29016,"others_contract_sig":"3045022100f27ddf1a06f0a809f6f2c0290c083aeb0249edcf3712a4013cbb49eaad9d73c2022072cd5ce7ad43ba92faf4fab124b523ab9da73fb80bfa0ce143294538d60b9bea","hash_preimage":[85,27,168,84,140,241,73,36,188,202,103,101,170,155,11,229,168,233,186,41,38,213,210,70,31,62,218,123,219,210,78,25]},{"my_privkey":"47cce522e8ee770dc3f66adfec1f8afce8ebcd2c4c2123ddcc5f844837f90043","other_pubkey":"023877681a076cf617fecefa22f052f91dac49bdaf3e82a9e27c458b071e944da2","other_privkey":"d368dbd0cc5572c6f2ee62c09bdcfc95bd4f4ef4f9d6bf007c9610e1a1e6f16d","contract_tx":{"version":2,"lock_time":0,"input":[{"previous_output":"856e89866ee5f987267d52cb0be0dba1c470aa88fb8f05fea68155674c85a922:1","script_sig":"","sequence":0,"witness":[]}],"output":[{"value":45797,"script_pubkey":"002052e776e090b83e7374d38322f3f3d15eafd18a42cda28509852674bc50ab4dec"}]},"contract_redeemscript":"827ca914e72c34a16c087526a7b5947ccca2419c983d08468763210256413ee5a8ba7f29a247cf90d80aa154cb5325c1363b946b913c7a8e54320e7001205167210364222a38a6c5178cad7f0eb4359dac793f3f7582117203134b88e77dcf87ba5900016068b2757b88ac","hashlock_privkey":"8147fe08b6cdf996bb74a04a4bd748735815a3c79adc85dc34237cc8879809dc","funding_amount":46797,"others_contract_sig":"304402200ce9be5c295817d13fc5f2d74bc8c556c3413d7f72a19b405933da951e698c3a02204ad706afb0c45f9028f3c77ce5d90aa97be2b7b31a4bf1af8ad06e2b7de38245","hash_preimage":[85,27,168,84,140,241,73,36,188,202,103,101,170,155,11,229,168,233,186,41,38,213,210,70,31,62,218,123,219,210,78,25]},{"my_privkey":"9d97b33216504b307b508a8058a38fe223d2e8bf6c81b57891c0259110560c12","other_pubkey":"03e4478f5a873a1cc56bdfeecaec8b467a09db78797ac6681464daa870a404b88f","other_privkey":"452ef3aa47a122231256f24b915c19505a5cc90654bd2d5d56c538555936ef97","contract_tx":{"version":2,"lock_time":0,"input":[{"previous_output":"ecb6ddd1590e2dd31d7e119759615d249db49c50653ce140101d8cab29408d63:0","script_sig":"","sequence":0,"witness":[]}],"output":[{"value":416071,"script_pubkey":"00207caff66487dca1f522509847529319dc6e69f05b28e1f734cf440c04c6a7dd25"}]},"contract_redeemscript":"827ca914e72c34a16c087526a7b5947ccca2419c983d084687632103cf5ff926028d72948ade0aa5a20c9e949ab5fb07e7b168219a01bd2b7b61087a0120516721039f2c2d56b359def059e30ae041aab73857a98861941c5b279b156754c220025c00016068b2757b88ac","hashlock_privkey":"064515149649f972c89ee8c21b46ca991dca072318a4bc1fa63c550cff4837b4","funding_amount":417071,"others_contract_sig":"30440220758008bb6afb08d39aebff5427a07d7fd5a07b723055d9b5e33e48edf28e6624022041cb98841ff1c398726ca8de471bbe65cbe0b88932d634f3f6031561c595484e","hash_preimage":[85,27,168,84,140,241,73,36,188,202,103,101,170,155,11,229,168,233,186,41,38,213,210,70,31,62,218,123,219,210,78,25]}],"outgoing_swapcoins":[{"my_privkey":"2748e867de7defe802439a9dcf8c0e6e6dc7789d710c0c91c14f8098176587f2","other_pubkey":"020454a50259c141ab00762dc813605c0088d5b639138c8fe241cb7b93821ae8e1","contract_tx":{"version":2,"lock_time":0,"input":[{"previous_output":"513c85f573dfe01b0a1320b615c0e80fb8e4ed4cf5c3230649b19fd9479cb3c3:1","script_sig":"","sequence":0,"witness":[]}],"output":[{"value":126301,"script_pubkey":"0020c05abd0c969fd209c7c3213d7e7f825f8b33ad4e8e263e2821bf4fb66b7ddebe"}]},"contract_redeemscript":"827ca914e72c34a16c087526a7b5947ccca2419c983d084687632102b21701ec7351335e653d128b00eb8b0f13e89b82585f4349bd48a685245171e90120516721038a5ebb4b1fbaf6ebf8788808e33b18872bcc3df78cb05c3588e48966de5ae2cf00013068b2757b88ac","timelock_privkey":"0761ae7fff03f91b3ee0a84991a8db75cbb6db8f1054788ece7b0fadfb1f08ca","funding_amount":127301,"others_contract_sig":"30450221009182bd72d52a89c664630ae233981cb43d8144c936362a00e6f7c26dbe23e1b0022028f68729b6aca2de3342383e320693939d08d2f8a6c87936ed87d470c2d97385","hash_preimage":null},{"my_privkey":"622e5981f7f5e0cc9b6f32093d4e35e39d4b7475a266889dcc95224a588f12c8","other_pubkey":"0251ac03c8d78280a917fac9d20e9de11394ea602f6470c0e0e8eada1d637e9828","contract_tx":{"version":2,"lock_time":0,"input":[{"previous_output":"8858cae967218debb3374970b18dd0839bc44da33786142718fa797c799011d9:0","script_sig":"","sequence":0,"witness":[]}],"output":[{"value":190762,"script_pubkey":"002031f0e355e3b242fdf5f895ecf13c19ff687ed0111adc3dc4bd5d78e1f8b2837f"}]},"contract_redeemscript":"827ca914e72c34a16c087526a7b5947ccca2419c983d084687632103668e776d22c5ecce24ea8932004c4c9eaf6d230a0bcc5a012dcff742ee52356c012051672103b4ea1f89ba0659dc180e2120836043c3c61238ed3f607b8f556b47b5af51614200013068b2757b88ac","timelock_privkey":"7f66c2f50e43e9bfdf995208b4aa2421c6330e19e790caf4f61e2994da0e8fce","funding_amount":191762,"others_contract_sig":"3045022100f77f2f5ced9a48ef3ad45ef212048ce127d0e0c39fbe755596e21670a2cf38d9022021f027b4e4eb2917d904e4139130d5ced604eae6172b6e2bcfc3f62dc140171a","hash_preimage":null},{"my_privkey":"f86a5830e91e10faac48f368a29522b00bda46a9a4342265cf1795d274f9269d","other_pubkey":"029152b0a71f1288474bbd0817a2952a7fde7684a6ea01cb63726f0bcdabef4cce","contract_tx":{"version":2,"lock_time":0,"input":[{"previous_output":"0c429480e51957c6855c52e3dd961888ad8c622767382bc5cf0426f94025d9c5:1","script_sig":"","sequence":0,"witness":[]}],"output":[{"value":165777,"script_pubkey":"00205befbc766c8a944b0a4913bc497309e21a7adb6540c04437333f31fb2170c8cd"}]},"contract_redeemscript":"827ca914e72c34a16c087526a7b5947ccca2419c983d0846876321026a69d1209e627756e2c4fea014ab5f58889b3310eb5e428aa7cea9989c991c2a012051672103427592e8e2fb4c6e7e8317bdb376c5a7d19453afc75d80ebc97d7e6dd98c965c00013068b2757b88ac","timelock_privkey":"89ae838cc65de51955d300fc333407b1bb3f442b776173bae9273c3f84a111e4","funding_amount":166777,"others_contract_sig":"3044022100bf3bb6f7da7c56d80ad88d916fb886fe9abf8d5eadd44ee302257397aac6b810021f3a595f29a502a4737ef365285e6eb85257fcf338b8981aed6ee839970d2e63","hash_preimage":null}],"prevout_to_contract_map":{}}

After (this CBOR data has been decoded using cbor.dev to make it readable)

Click to view

{ "file_name": "maker16102", "version": 0, "network": "regtest", "seedphrase": "illegal correct weekend viable myth assume fence reason among sick trick elbow", "passphrase": "", "external_index": 0, "incoming_swapcoins": [ { "my_privkey": [ 220, 156, 123, 102, 153, 65, 115, 241, 197, 178, 253, 132, 192, 141, 136, 215, 21, 237, 196, 199, 131, 177, 63, 196, 218, 189, 226, 249, 90, 229, 223, 40 ], "other_pubkey": { "0": 2, "1": 61, "2": 122, "3": 40, "4": 140, "5": 0, "6": 20, "7": 254, "8": 203, "9": 84, "10": 180, "11": 173, "12": 147, "13": 89, "14": 151, "15": 212, "16": 40, "17": 82, "18": 62, "19": 61, "20": 70, "21": 146, "22": 229, "23": 71, "24": 186, "25": 67, "26": 147, "27": 133, "28": 155, "29": 69, "30": 47, "31": 163, "32": 223 }, "other_privkey": [ 91, 183, 252, 167, 48, 252, 213, 114, 253, 3, 218, 225, 97, 199, 188, 93, 111, 196, 197, 160, 132, 162, 31, 59, 92, 68, 4, 181, 238, 45, 174, 253 ], "contract_tx": { "version": 2, "lock_time": 0, "input": [ { "previous_output": { "txid": { "0": 174, "1": 122, "2": 17, "3": 131, "4": 20, "5": 221, "6": 23, "7": 16, "8": 165, "9": 159, "10": 136, "11": 85, "12": 74, "13": 186, "14": 62, "15": 78, "16": 85, "17": 159, "18": 185, "19": 121, "20": 221, "21": 160, "22": 177, "23": 65, "24": 239, "25": 222, "26": 167, "27": 95, "28": 142, "29": 115, "30": 43, "31": 233 }, "vout": 1 }, "script_sig": {}, "sequence": 0, "witness": [] } ], "output": [ { "value": 17222, "script_pubkey": { "0": 0, "1": 32, "2": 222, "3": 112, "4": 150, "5": 31, "6": 239, "7": 126, "8": 192, "9": 176, "10": 29, "11": 157, "12": 130, "13": 205, "14": 46, "15": 82, "16": 116, "17": 136, "18": 131, "19": 167, "20": 162, "21": 65, "22": 169, "23": 139, "24": 68, "25": 141, "26": 196, "27": 141, "28": 84, "29": 135, "30": 185, "31": 186, "32": 71, "33": 101 } } ] }, "contract_redeemscript": { "0": 130, "1": 124, "2": 169, "3": 20, "4": 220, "5": 166, "6": 28, "7": 105, "8": 108, "9": 70, "10": 101, "11": 237, "12": 155, "13": 31, "14": 89, "15": 217, "16": 3, "17": 163, "18": 76, "19": 2, "20": 68, "21": 86, "22": 101, "23": 225, "24": 135, "25": 99, "26": 33, "27": 3, "28": 48, "29": 243, "30": 207, "31": 34, "32": 172, "33": 17, "34": 74, "35": 81, "36": 224, "37": 44, "38": 109, "39": 15, "40": 234, "41": 29, "42": 192, "43": 244, "44": 253, "45": 108, "46": 10, "47": 234, "48": 200, "49": 5, "50": 170, "51": 212, "52": 202, "53": 164, "54": 9, "55": 173, "56": 159, "57": 245, "58": 199, "59": 253, "60": 1, "61": 32, "62": 81, "63": 103, "64": 33, "65": 2, "66": 83, "67": 193, "68": 175, "69": 51, "70": 188, "71": 160, "72": 154, "73": 72, "74": 172, "75": 145, "76": 6, "77": 140, "78": 195, "79": 165, "80": 38, "81": 65, "82": 138, "83": 238, "84": 226, "85": 238, "86": 79, "87": 114, "88": 165, "89": 15, "90": 107, "91": 91, "92": 74, "93": 73, "94": 249, "95": 238, "96": 10, "97": 61, "98": 0, "99": 2, "100": 144, "101": 0, "102": 104, "103": 178, "104": 117, "105": 123, "106": 136, "107": 172 }, "hashlock_privkey": [ 24, 193, 184, 77, 95, 186, 65, 96, 27, 220, 145, 247, 27, 232, 99, 134, 161, 202, 15, 132, 7, 72, 250, 231, 87, 36, 135, 134, 13, 116, 60, 28 ], "funding_amount": 18222, "others_contract_sig": { "0": 48, "1": 69, "2": 2, "3": 33, "4": 0, "5": 215, "6": 127, "7": 128, "8": 154, "9": 238, "10": 157, "11": 88, "12": 185, "13": 219, "14": 207, "15": 150, "16": 179, "17": 253, "18": 22, "19": 228, "20": 59, "21": 122, "22": 255, "23": 222, "24": 102, "25": 33, "26": 168, "27": 73, "28": 239, "29": 22, "30": 38, "31": 109, "32": 29, "33": 189, "34": 1, "35": 254, "36": 49, "37": 2, "38": 32, "39": 17, "40": 78, "41": 60, "42": 105, "43": 201, "44": 90, "45": 213, "46": 234, "47": 142, "48": 248, "49": 82, "50": 249, "51": 119, "52": 22, "53": 129, "54": 88, "55": 196, "56": 185, "57": 36, "58": 40, "59": 6, "60": 159, "61": 146, "62": 136, "63": 6, "64": 89, "65": 255, "66": 156, "67": 79, "68": 22, "69": 68, "70": 91 }, "hash_preimage": [ 106, 54, 151, 179, 46, 87, 58, 209, 165, 76, 52, 186, 126, 14, 92, 201, 66, 118, 214, 69, 222, 131, 25, 96, 119, 212, 123, 60, 53, 228, 17, 159 ] }, { "my_privkey": [ 74, 74, 203, 150, 216, 207, 106, 65, 49, 126, 64, 226, 40, 96, 171, 83, 229, 199, 181, 217, 197, 199, 221, 212, 68, 208, 193, 253, 143, 83, 83, 60 ], "other_pubkey": { "0": 3, "1": 30, "2": 181, "3": 45, "4": 142, "5": 48, "6": 105, "7": 171, "8": 17, "9": 106, "10": 243, "11": 147, "12": 61, "13": 246, "14": 117, "15": 241, "16": 51, "17": 101, "18": 12, "19": 84, "20": 220, "21": 245, "22": 106, "23": 104, "24": 166, "25": 4, "26": 90, "27": 123, "28": 70, "29": 85, "30": 34, "31": 213, "32": 23 }, "other_privkey": [ 52, 47, 0, 18, 157, 230, 130, 46, 195, 244, 90, 23, 210, 25, 47, 190, 247, 36, 249, 38, 139, 217, 229, 10, 235, 90, 95, 102, 164, 88, 242, 137 ], "contract_tx": { "version": 2, "lock_time": 0, "input": [ { "previous_output": { "txid": { "0": 233, "1": 156, "2": 249, "3": 196, "4": 48, "5": 92, "6": 176, "7": 86, "8": 153, "9": 152, "10": 166, "11": 103, "12": 108, "13": 1, "14": 35, "15": 254, "16": 57, "17": 122, "18": 94, "19": 110, "20": 176, "21": 17, "22": 150, "23": 73, "24": 113, "25": 204, "26": 110, "27": 229, "28": 231, "29": 78, "30": 204, "31": 185 }, "vout": 0 }, "script_sig": {}, "sequence": 0, "witness": [] } ], "output": [ { "value": 185026, "script_pubkey": { "0": 0, "1": 32, "2": 72, "3": 155, "4": 156, "5": 150, "6": 10, "7": 141, "8": 197, "9": 242, "10": 82, "11": 174, "12": 237, "13": 206, "14": 2, "15": 143, "16": 177, "17": 172, "18": 225, "19": 126, "20": 227, "21": 30, "22": 202, "23": 62, "24": 4, "25": 105, "26": 20, "27": 32, "28": 111, "29": 22, "30": 219, "31": 147, "32": 71, "33": 112 } } ] }, "contract_redeemscript": { "0": 130, "1": 124, "2": 169, "3": 20, "4": 220, "5": 166, "6": 28, "7": 105, "8": 108, "9": 70, "10": 101, "11": 237, "12": 155, "13": 31, "14": 89, "15": 217, "16": 3, "17": 163, "18": 76, "19": 2, "20": 68, "21": 86, "22": 101, "23": 225, "24": 135, "25": 99, "26": 33, "27": 2, "28": 153, "29": 94, "30": 235, "31": 220, "32": 174, "33": 196, "34": 104, "35": 54, "36": 176, "37": 93, "38": 42, "39": 127, "40": 4, "41": 43, "42": 63, "43": 60, "44": 14, "45": 156, "46": 184, "47": 127, "48": 123, "49": 65, "50": 54, "51": 208, "52": 91, "53": 127, "54": 37, "55": 103, "56": 170, "57": 15, "58": 118, "59": 181, "60": 1, "61": 32, "62": 81, "63": 103, "64": 33, "65": 3, "66": 255, "67": 203, "68": 114, "69": 220, "70": 219, "71": 205, "72": 60, "73": 58, "74": 192, "75": 13, "76": 182, "77": 202, "78": 240, "79": 116, "80": 225, "81": 57, "82": 6, "83": 192, "84": 128, "85": 218, "86": 196, "87": 0, "88": 119, "89": 57, "90": 72, "91": 99, "92": 205, "93": 190, "94": 238, "95": 195, "96": 141, "97": 11, "98": 0, "99": 2, "100": 144, "101": 0, "102": 104, "103": 178, "104": 117, "105": 123, "106": 136, "107": 172 }, "hashlock_privkey": [ 23, 135, 17, 218, 218, 190, 133, 210, 195, 33, 167, 25, 32, 97, 23, 111, 14, 208, 119, 177, 138, 142, 148, 213, 208, 183, 41, 227, 34, 141, 240, 247 ], "funding_amount": 186026, "others_contract_sig": { "0": 48, "1": 68, "2": 2, "3": 32, "4": 57, "5": 50, "6": 8, "7": 119, "8": 234, "9": 182, "10": 230, "11": 95, "12": 57, "13": 136, "14": 47, "15": 146, "16": 229, "17": 136, "18": 144, "19": 196, "20": 150, "21": 208, "22": 34, "23": 205, "24": 226, "25": 216, "26": 116, "27": 207, "28": 135, "29": 165, "30": 210, "31": 163, "32": 230, "33": 108, "34": 23, "35": 98, "36": 2, "37": 32, "38": 34, "39": 181, "40": 253, "41": 119, "42": 141, "43": 201, "44": 88, "45": 218, "46": 26, "47": 164, "48": 155, "49": 214, "50": 24, "51": 101, "52": 5, "53": 206, "54": 29, "55": 60, "56": 233, "57": 62, "58": 110, "59": 252, "60": 221, "61": 42, "62": 153, "63": 125, "64": 79, "65": 223, "66": 89, "67": 39, "68": 101, "69": 112 }, "hash_preimage": [ 106, 54, 151, 179, 46, 87, 58, 209, 165, 76, 52, 186, 126, 14, 92, 201, 66, 118, 214, 69, 222, 131, 25, 96, 119, 212, 123, 60, 53, 228, 17, 159 ] }, { "my_privkey": [ 101, 151, 248, 125, 188, 63, 46, 206, 73, 204, 151, 181, 86, 251, 12, 88, 19, 12, 156, 36, 169, 174, 93, 56, 220, 49, 10, 83, 164, 19, 174, 168 ], "other_pubkey": { "0": 2, "1": 136, "2": 195, "3": 87, "4": 129, "5": 70, "6": 126, "7": 78, "8": 141, "9": 244, "10": 165, "11": 110, "12": 225, "13": 153, "14": 72, "15": 50, "16": 92, "17": 25, "18": 20, "19": 233, "20": 51, "21": 87, "22": 58, "23": 213, "24": 83, "25": 221, "26": 151, "27": 199, "28": 132, "29": 78, "30": 103, "31": 75, "32": 160 }, "other_privkey": [ 149, 231, 44, 208, 180, 238, 139, 66, 63, 97, 44, 234, 112, 151, 238, 14, 107, 134, 201, 20, 30, 162, 251, 148, 130, 228, 245, 96, 76, 97, 186, 92 ], "contract_tx": { "version": 2, "lock_time": 0, "input": [ { "previous_output": { "txid": { "0": 230, "1": 160, "2": 105, "3": 234, "4": 252, "5": 176, "6": 237, "7": 33, "8": 211, "9": 56, "10": 92, "11": 76, "12": 137, "13": 6, "14": 1, "15": 81, "16": 204, "17": 128, "18": 176, "19": 155, "20": 175, "21": 75, "22": 49, "23": 16, "24": 62, "25": 134, "26": 62, "27": 116, "28": 62, "29": 232, "30": 112, "31": 169 }, "vout": 1 }, "script_sig": {}, "sequence": 0, "witness": [] } ], "output": [ { "value": 294752, "script_pubkey": { "0": 0, "1": 32, "2": 235, "3": 158, "4": 181, "5": 148, "6": 64, "7": 142, "8": 2, "9": 10, "10": 212, "11": 92, "12": 71, "13": 194, "14": 190, "15": 23, "16": 154, "17": 222, "18": 38, "19": 175, "20": 216, "21": 40, "22": 100, "23": 0, "24": 90, "25": 154, "26": 4, "27": 253, "28": 131, "29": 224, "30": 75, "31": 2, "32": 107, "33": 221 } } ] }, "contract_redeemscript": { "0": 130, "1": 124, "2": 169, "3": 20, "4": 220, "5": 166, "6": 28, "7": 105, "8": 108, "9": 70, "10": 101, "11": 237, "12": 155, "13": 31, "14": 89, "15": 217, "16": 3, "17": 163, "18": 76, "19": 2, "20": 68, "21": 86, "22": 101, "23": 225, "24": 135, "25": 99, "26": 33, "27": 2, "28": 196, "29": 20, "30": 157, "31": 210, "32": 186, "33": 135, "34": 11, "35": 137, "36": 240, "37": 205, "38": 107, "39": 25, "40": 11, "41": 75, "42": 22, "43": 99, "44": 227, "45": 150, "46": 254, "47": 29, "48": 91, "49": 252, "50": 71, "51": 246, "52": 212, "53": 200, "54": 210, "55": 139, "56": 31, "57": 217, "58": 50, "59": 90, "60": 1, "61": 32, "62": 81, "63": 103, "64": 33, "65": 2, "66": 208, "67": 251, "68": 55, "69": 71, "70": 129, "71": 139, "72": 56, "73": 231, "74": 165, "75": 229, "76": 186, "77": 128, "78": 6, "79": 8, "80": 33, "81": 178, "82": 235, "83": 194, "84": 156, "85": 237, "86": 90, "87": 19, "88": 226, "89": 154, "90": 131, "91": 208, "92": 16, "93": 147, "94": 106, "95": 254, "96": 137, "97": 85, "98": 0, "99": 2, "100": 144, "101": 0, "102": 104, "103": 178, "104": 117, "105": 123, "106": 136, "107": 172 }, "hashlock_privkey": [ 52, 131, 52, 119, 108, 104, 14, 49, 254, 100, 35, 5, 243, 191, 226, 228, 20, 248, 61, 10, 202, 77, 171, 3, 186, 199, 136, 9, 104, 227, 99, 203 ], "funding_amount": 295752, "others_contract_sig": { "0": 48, "1": 68, "2": 2, "3": 32, "4": 113, "5": 157, "6": 173, "7": 251, "8": 38, "9": 206, "10": 26, "11": 111, "12": 230, "13": 76, "14": 222, "15": 252, "16": 186, "17": 229, "18": 167, "19": 205, "20": 225, "21": 140, "22": 250, "23": 51, "24": 155, "25": 208, "26": 194, "27": 174, "28": 167, "29": 251, "30": 205, "31": 178, "32": 42, "33": 169, "34": 63, "35": 223, "36": 2, "37": 32, "38": 74, "39": 175, "40": 127, "41": 253, "42": 27, "43": 30, "44": 72, "45": 188, "46": 121, "47": 208, "48": 64, "49": 192, "50": 163, "51": 31, "52": 135, "53": 157, "54": 174, "55": 154, "56": 145, "57": 134, "58": 219, "59": 68, "60": 176, "61": 14, "62": 67, "63": 156, "64": 174, "65": 68, "66": 199, "67": 24, "68": 79, "69": 24 }, "hash_preimage": [ 106, 54, 151, 179, 46, 87, 58, 209, 165, 76, 52, 186, 126, 14, 92, 201, 66, 118, 214, 69, 222, 131, 25, 96, 119, 212, 123, 60, 53, 228, 17, 159 ] } ], "outgoing_swapcoins": [ { "my_privkey": [ 168, 179, 83, 203, 159, 132, 186, 146, 158, 82, 139, 205, 236, 114, 43, 35, 35, 161, 138, 249, 37, 78, 232, 61, 245, 58, 237, 82, 120, 10, 245, 64 ], "other_pubkey": { "0": 2, "1": 122, "2": 160, "3": 136, "4": 129, "5": 233, "6": 53, "7": 95, "8": 46, "9": 204, "10": 110, "11": 136, "12": 19, "13": 177, "14": 89, "15": 124, "16": 122, "17": 234, "18": 236, "19": 69, "20": 234, "21": 57, "22": 88, "23": 169, "24": 79, "25": 113, "26": 247, "27": 85, "28": 242, "29": 69, "30": 182, "31": 25, "32": 231 }, "contract_tx": { "version": 2, "lock_time": 0, "input": [ { "previous_output": { "txid": { "0": 252, "1": 45, "2": 112, "3": 89, "4": 237, "5": 229, "6": 24, "7": 46, "8": 0, "9": 59, "10": 221, "11": 97, "12": 68, "13": 122, "14": 30, "15": 19, "16": 243, "17": 90, "18": 165, "19": 130, "20": 245, "21": 21, "22": 33, "23": 190, "24": 203, "25": 42, "26": 48, "27": 146, "28": 190, "29": 188, "30": 190, "31": 202 }, "vout": 0 }, "script_sig": {}, "sequence": 0, "witness": [] } ], "output": [ { "value": 418855, "script_pubkey": { "0": 0, "1": 32, "2": 121, "3": 190, "4": 130, "5": 220, "6": 68, "7": 53, "8": 188, "9": 37, "10": 149, "11": 115, "12": 99, "13": 214, "14": 10, "15": 41, "16": 95, "17": 107, "18": 180, "19": 69, "20": 219, "21": 244, "22": 213, "23": 252, "24": 43, "25": 112, "26": 151, "27": 43, "28": 73, "29": 128, "30": 37, "31": 32, "32": 137, "33": 248 } } ] }, "contract_redeemscript": { "0": 130, "1": 124, "2": 169, "3": 20, "4": 220, "5": 166, "6": 28, "7": 105, "8": 108, "9": 70, "10": 101, "11": 237, "12": 155, "13": 31, "14": 89, "15": 217, "16": 3, "17": 163, "18": 76, "19": 2, "20": 68, "21": 86, "22": 101, "23": 225, "24": 135, "25": 99, "26": 33, "27": 2, "28": 50, "29": 41, "30": 195, "31": 153, "32": 62, "33": 108, "34": 174, "35": 30, "36": 51, "37": 52, "38": 241, "39": 23, "40": 35, "41": 139, "42": 153, "43": 108, "44": 22, "45": 192, "46": 109, "47": 84, "48": 211, "49": 212, "50": 61, "51": 2, "52": 71, "53": 153, "54": 142, "55": 192, "56": 17, "57": 49, "58": 129, "59": 228, "60": 1, "61": 32, "62": 81, "63": 103, "64": 33, "65": 2, "66": 19, "67": 245, "68": 86, "69": 131, "70": 127, "71": 158, "72": 225, "73": 249, "74": 171, "75": 160, "76": 99, "77": 179, "78": 205, "79": 242, "80": 152, "81": 202, "82": 50, "83": 82, "84": 138, "85": 234, "86": 210, "87": 131, "88": 69, "89": 110, "90": 69, "91": 85, "92": 116, "93": 113, "94": 112, "95": 83, "96": 73, "97": 242, "98": 0, "99": 1, "100": 96, "101": 104, "102": 178, "103": 117, "104": 123, "105": 136, "106": 172 }, "timelock_privkey": [ 66, 196, 202, 88, 211, 144, 253, 234, 159, 226, 206, 48, 122, 142, 66, 2, 31, 113, 147, 94, 97, 2, 123, 209, 69, 209, 67, 63, 242, 124, 141, 94 ], "funding_amount": 419855, "others_contract_sig": { "0": 48, "1": 69, "2": 2, "3": 33, "4": 0, "5": 241, "6": 186, "7": 196, "8": 106, "9": 54, "10": 164, "11": 189, "12": 22, "13": 87, "14": 254, "15": 204, "16": 64, "17": 221, "18": 91, "19": 205, "20": 236, "21": 254, "22": 219, "23": 181, "24": 127, "25": 31, "26": 120, "27": 3, "28": 79, "29": 232, "30": 151, "31": 146, "32": 35, "33": 169, "34": 228, "35": 167, "36": 247, "37": 2, "38": 32, "39": 43, "40": 124, "41": 231, "42": 210, "43": 68, "44": 170, "45": 59, "46": 122, "47": 182, "48": 227, "49": 43, "50": 142, "51": 246, "52": 240, "53": 242, "54": 27, "55": 164, "56": 216, "57": 114, "58": 169, "59": 157, "60": 177, "61": 13, "62": 240, "63": 24, "64": 90, "65": 191, "66": 20, "67": 196, "68": 63, "69": 200, "70": 70 }, "hash_preimage": null }, { "my_privkey": [ 141, 26, 148, 34, 40, 66, 80, 52, 238, 179, 245, 222, 70, 22, 96, 71, 183, 219, 70, 168, 93, 63, 9, 236, 40, 228, 94, 253, 63, 52, 35, 162 ], "other_pubkey": { "0": 2, "1": 94, "2": 164, "3": 136, "4": 140, "5": 109, "6": 67, "7": 29, "8": 113, "9": 182, "10": 174, "11": 165, "12": 234, "13": 49, "14": 11, "15": 54, "16": 112, "17": 12, "18": 220, "19": 219, "20": 233, "21": 104, "22": 124, "23": 46, "24": 35, "25": 79, "26": 100, "27": 106, "28": 110, "29": 167, "30": 61, "31": 86, "32": 148 }, "contract_tx": { "version": 2, "lock_time": 0, "input": [ { "previous_output": { "txid": { "0": 222, "1": 116, "2": 117, "3": 96, "4": 212, "5": 188, "6": 224, "7": 33, "8": 167, "9": 209, "10": 99, "11": 134, "12": 43, "13": 24, "14": 105, "15": 245, "16": 38, "17": 65, "18": 10, "19": 80, "20": 68, "21": 255, "22": 19, "23": 11, "24": 180, "25": 250, "26": 135, "27": 234, "28": 253, "29": 26, "30": 212, "31": 184 }, "vout": 1 }, "script_sig": {}, "sequence": 0, "witness": [] } ], "output": [ { "value": 38135, "script_pubkey": { "0": 0, "1": 32, "2": 154, "3": 210, "4": 248, "5": 43, "6": 56, "7": 32, "8": 63, "9": 241, "10": 68, "11": 241, "12": 197, "13": 93, "14": 4, "15": 235, "16": 139, "17": 218, "18": 64, "19": 191, "20": 34, "21": 217, "22": 68, "23": 225, "24": 124, "25": 173, "26": 111, "27": 111, "28": 138, "29": 175, "30": 115, "31": 12, "32": 58, "33": 33 } } ] }, "contract_redeemscript": { "0": 130, "1": 124, "2": 169, "3": 20, "4": 220, "5": 166, "6": 28, "7": 105, "8": 108, "9": 70, "10": 101, "11": 237, "12": 155, "13": 31, "14": 89, "15": 217, "16": 3, "17": 163, "18": 76, "19": 2, "20": 68, "21": 86, "22": 101, "23": 225, "24": 135, "25": 99, "26": 33, "27": 2, "28": 246, "29": 73, "30": 148, "31": 70, "32": 14, "33": 10, "34": 82, "35": 44, "36": 39, "37": 231, "38": 94, "39": 115, "40": 103, "41": 87, "42": 185, "43": 245, "44": 82, "45": 92, "46": 245, "47": 184, "48": 207, "49": 75, "50": 242, "51": 16, "52": 148, "53": 239, "54": 15, "55": 34, "56": 250, "57": 173, "58": 143, "59": 38, "60": 1, "61": 32, "62": 81, "63": 103, "64": 33, "65": 2, "66": 144, "67": 41, "68": 202, "69": 103, "70": 6, "71": 175, "72": 230, "73": 248, "74": 34, "75": 109, "76": 117, "77": 6, "78": 213, "79": 20, "80": 210, "81": 202, "82": 82, "83": 170, "84": 186, "85": 103, "86": 228, "87": 39, "88": 59, "89": 42, "90": 76, "91": 146, "92": 115, "93": 242, "94": 96, "95": 163, "96": 65, "97": 138, "98": 0, "99": 1, "100": 96, "101": 104, "102": 178, "103": 117, "104": 123, "105": 136, "106": 172 }, "timelock_privkey": [ 19, 125, 204, 227, 116, 97, 106, 31, 167, 96, 94, 65, 147, 180, 14, 19, 0, 203, 106, 8, 3, 19, 5, 150, 134, 80, 102, 132, 91, 38, 69, 20 ], "funding_amount": 39135, "others_contract_sig": { "0": 48, "1": 69, "2": 2, "3": 33, "4": 0, "5": 236, "6": 128, "7": 18, "8": 47, "9": 7, "10": 95, "11": 7, "12": 74, "13": 70, "14": 129, "15": 220, "16": 62, "17": 231, "18": 237, "19": 74, "20": 93, "21": 48, "22": 157, "23": 23, "24": 47, "25": 26, "26": 26, "27": 182, "28": 213, "29": 242, "30": 140, "31": 255, "32": 230, "33": 131, "34": 94, "35": 199, "36": 114, "37": 2, "38": 32, "39": 5, "40": 0, "41": 78, "42": 96, "43": 71, "44": 144, "45": 141, "46": 122, "47": 68, "48": 111, "49": 82, "50": 82, "51": 57, "52": 239, "53": 105, "54": 17, "55": 119, "56": 176, "57": 27, "58": 213, "59": 38, "60": 168, "61": 64, "62": 229, "63": 133, "64": 218, "65": 88, "66": 140, "67": 35, "68": 211, "69": 23, "70": 123 }, "hash_preimage": null }, { "my_privkey": [ 123, 201, 39, 210, 37, 230, 252, 190, 221, 16, 23, 63, 54, 237, 15, 214, 166, 91, 124, 66, 205, 138, 222, 7, 180, 28, 193, 186, 94, 206, 75, 23 ], "other_pubkey": { "0": 2, "1": 195, "2": 117, "3": 112, "4": 64, "5": 126, "6": 133, "7": 57, "8": 85, "9": 165, "10": 108, "11": 45, "12": 171, "13": 244, "14": 34, "15": 137, "16": 141, "17": 16, "18": 20, "19": 105, "20": 58, "21": 131, "22": 231, "23": 218, "24": 52, "25": 136, "26": 240, "27": 37, "28": 14, "29": 137, "30": 37, "31": 78, "32": 253 }, "contract_tx": { "version": 2, "lock_time": 0, "input": [ { "previous_output": { "txid": { "0": 183, "1": 237, "2": 153, "3": 145, "4": 94, "5": 22, "6": 228, "7": 26, "8": 34, "9": 65, "10": 20, "11": 67, "12": 224, "13": 241, "14": 52, "15": 109, "16": 142, "17": 195, "18": 153, "19": 165, "20": 91, "21": 75, "22": 249, "23": 152, "24": 70, "25": 151, "26": 31, "27": 61, "28": 90, "29": 188, "30": 176, "31": 69 }, "vout": 1 }, "script_sig": {}, "sequence": 0, "witness": [] } ], "output": [ { "value": 32894, "script_pubkey": { "0": 0, "1": 32, "2": 126, "3": 91, "4": 9, "5": 9, "6": 181, "7": 57, "8": 18, "9": 224, "10": 94, "11": 78, "12": 81, "13": 89, "14": 244, "15": 146, "16": 104, "17": 89, "18": 243, "19": 208, "20": 12, "21": 16, "22": 22, "23": 159, "24": 84, "25": 110, "26": 47, "27": 104, "28": 23, "29": 119, "30": 121, "31": 38, "32": 23, "33": 231 } } ] }, "contract_redeemscript": { "0": 130, "1": 124, "2": 169, "3": 20, "4": 220, "5": 166, "6": 28, "7": 105, "8": 108, "9": 70, "10": 101, "11": 237, "12": 155, "13": 31, "14": 89, "15": 217, "16": 3, "17": 163, "18": 76, "19": 2, "20": 68, "21": 86, "22": 101, "23": 225, "24": 135, "25": 99, "26": 33, "27": 3, "28": 94, "29": 85, "30": 156, "31": 192, "32": 28, "33": 93, "34": 103, "35": 108, "36": 23, "37": 191, "38": 169, "39": 36, "40": 188, "41": 249, "42": 249, "43": 171, "44": 127, "45": 87, "46": 149, "47": 112, "48": 64, "49": 147, "50": 83, "51": 159, "52": 204, "53": 86, "54": 151, "55": 184, "56": 193, "57": 63, "58": 87, "59": 154, "60": 1, "61": 32, "62": 81, "63": 103, "64": 33, "65": 2, "66": 226, "67": 172, "68": 88, "69": 83, "70": 243, "71": 193, "72": 216, "73": 99, "74": 207, "75": 3, "76": 102, "77": 105, "78": 61, "79": 39, "80": 228, "81": 208, "82": 52, "83": 85, "84": 124, "85": 226, "86": 148, "87": 75, "88": 249, "89": 253, "90": 238, "91": 124, "92": 23, "93": 116, "94": 222, "95": 93, "96": 149, "97": 74, "98": 0, "99": 1, "100": 96, "101": 104, "102": 178, "103": 117, "104": 123, "105": 136, "106": 172 }, "timelock_privkey": [ 91, 85, 224, 75, 150, 38, 53, 242, 54, 226, 205, 9, 248, 228, 168, 199, 13, 143, 226, 105, 164, 193, 140, 23, 235, 111, 121, 39, 11, 205, 139, 108 ], "funding_amount": 33894, "others_contract_sig": { "0": 48, "1": 68, "2": 2, "3": 32, "4": 2, "5": 64, "6": 80, "7": 94, "8": 162, "9": 26, "10": 219, "11": 38, "12": 41, "13": 244, "14": 178, "15": 71, "16": 27, "17": 159, "18": 65, "19": 195, "20": 205, "21": 203, "22": 163, "23": 204, "24": 36, "25": 193, "26": 80, "27": 253, "28": 25, "29": 2, "30": 222, "31": 188, "32": 95, "33": 167, "34": 181, "35": 14, "36": 2, "37": 32, "38": 107, "39": 127, "40": 37, "41": 97, "42": 85, "43": 184, "44": 63, "45": 241, "46": 83, "47": 56, "48": 13, "49": 197, "50": 107, "51": 113, "52": 23, "53": 20, "54": 136, "55": 29, "56": 97, "57": 195, "58": 69, "59": 27, "60": 228, "61": 68, "62": 91, "63": 46, "64": 104, "65": 127, "66": 115, "67": 53, "68": 255, "69": 116 }, "hash_preimage": null } ], "prevout_to_contract_map": {} }

Signed-off-by: wthrajat <rajatkhanduri290102@gmail.com>
@wthrajat wthrajat requested a review from a team January 22, 2024 14:23
Copy link

@rajarshimaitra rajarshimaitra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK.

src/wallet/error.rs Outdated Show resolved Hide resolved
@rajarshimaitra
Copy link

Example of a wallet file (out of many) before and after the PR is given below:

Any idea, how much size compression we achieved?

@wthrajat
Copy link
Collaborator Author

wthrajat commented Jan 23, 2024

@rajarshimaitra

Any idea, how much size compression we achieved?

28.72% compression!

How was the test done

I have the temp-files of before and after the PR saved with me.
Since they also contains many .bitcoin and configs folder, we can remove them and compare the size of only the wallet data.
(Be careful with the path so that you don't accidentally delete something)

find /path/to/temp-test-files \( -name ".bitcoin" -o -name "configs" \) -exec rm -rf {} +

After filtering out, we get 31 files inside 20 sub-folders

Before PR

Total size of all 31 .json wallet files is 260.5 KiB (2,66,750 bytes)

After PR

Total size of all 31 .cbor wallet files is 185.8 KiB (1,90,226 bytes)

Going by that we have achieved compression of 76,524 bytes, which represents a 28.72% decrease; noticeable difference in my opinion.

@rajarshimaitra
Copy link

rajarshimaitra commented Jan 23, 2024

Awesome!! now I think we can remove the whole serde_json dep in cargo.toml. Lets do it in this PR itself.

Also mark the Readme roadmap milestone.

Copy link

codecov bot commented Jan 23, 2024

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (928d2ee) 69.54% compared to head (17d8508) 69.32%.

Files Patch % Lines
src/wallet/error.rs 0.00% 4 Missing ⚠️
src/wallet/api.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #88      +/-   ##
==========================================
- Coverage   69.54%   69.32%   -0.22%     
==========================================
  Files          28       28              
  Lines        5808     5771      -37     
==========================================
- Hits         4039     4001      -38     
- Misses       1769     1770       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@rajarshimaitra rajarshimaitra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 17d8508

@rajarshimaitra rajarshimaitra merged commit e6dcd03 into citadel-tech:master Jan 23, 2024
8 checks passed
@wthrajat wthrajat self-assigned this Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: No status
Development

Successfully merging this pull request may close these issues.

improve: Binary encoding for wallet data
2 participants