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

Tx json #23

Merged
merged 13 commits into from
Jun 1, 2021
Merged

Tx json #23

merged 13 commits into from
Jun 1, 2021

Conversation

theflyingcodr
Copy link
Contributor

@theflyingcodr theflyingcodr commented May 6, 2021

Transactions can now be properly serialised and deserialised as JSON.

This is achieved by implementing a custom marshaler and unmarshaler which will produce JSON as shown:

{
	"version": 1,
	"locktime": 0,
	"txid": "41741af6fb64839c69f2385987eb3770c55c42eb6f7900fa2af9d667c42ceb20",
	"hash": "41741af6fb64839c69f2385987eb3770c55c42eb6f7900fa2af9d667c42ceb20",
	"size": 486,
	"hex": "0100000003d5da6f960610cc65153521fd16dbe96b499143ac8d03222c13a9b97ce2dd8e3c000000006b48304502210081214df575da1e9378f1d5a29dfd6811e93466a7222fb010b7c50dd2d44d7f2e0220399bb396336d2e294049e7db009926b1b30018ac834ee0cbca20b9d99f488038412102798913bc057b344de675dac34faafe3dc2f312c758cd9068209f810877306d66ffffffffd5da6f960610cc65153521fd16dbe96b499143ac8d03222c13a9b97ce2dd8e3c0200000069463043021f7059426d6aeb7d74275e52819a309b2bf903bd18b2b4d942d0e8e037681df702203f851f8a45aabfefdca5822f457609600f5d12a173adc09c6e7e2d4fdff7620a412102798913bc057b344de675dac34faafe3dc2f312c758cd9068209f810877306d66ffffffffd5da6f960610cc65153521fd16dbe96b499143ac8d03222c13a9b97ce2dd8e3c720000006b483045022100e7b3837f2818fe00a05293e0f90e9005d59b0c5c8890f22bd31c36190a9b55e9022027de4b77b78139ea21b9fd30876a447bbf29662bd19d7914028c607bccd772e4412102798913bc057b344de675dac34faafe3dc2f312c758cd9068209f810877306d66ffffffff01e8030000000000001976a914eb0bd5edba389198e73f8efabddfc61666969ff788ac00000000",
	"vin": [
		{
			"unlockingScript": {
				"asm": "304502210081214df575da1e9378f1d5a29dfd6811e93466a7222fb010b7c50dd2d44d7f2e0220399bb396336d2e294049e7db009926b1b30018ac834ee0cbca20b9d99f48803841 02798913bc057b344de675dac34faafe3dc2f312c758cd9068209f810877306d66",
				"hex": "48304502210081214df575da1e9378f1d5a29dfd6811e93466a7222fb010b7c50dd2d44d7f2e0220399bb396336d2e294049e7db009926b1b30018ac834ee0cbca20b9d99f488038412102798913bc057b344de675dac34faafe3dc2f312c758cd9068209f810877306d66"
			},
			"txid": "3c8edde27cb9a9132c22038dac4391496be9db16fd21351565cc1006966fdad5",
			"vout": 0,
			"sequence": 4294967295
		},
		{
			"unlockingScript": {
				"asm": "3043021f7059426d6aeb7d74275e52819a309b2bf903bd18b2b4d942d0e8e037681df702203f851f8a45aabfefdca5822f457609600f5d12a173adc09c6e7e2d4fdff7620a41 02798913bc057b344de675dac34faafe3dc2f312c758cd9068209f810877306d66",
				"hex": "463043021f7059426d6aeb7d74275e52819a309b2bf903bd18b2b4d942d0e8e037681df702203f851f8a45aabfefdca5822f457609600f5d12a173adc09c6e7e2d4fdff7620a412102798913bc057b344de675dac34faafe3dc2f312c758cd9068209f810877306d66"
			},
			"txid": "3c8edde27cb9a9132c22038dac4391496be9db16fd21351565cc1006966fdad5",
			"vout": 2,
			"sequence": 4294967295
		},
		{
			"unlockingScript": {
				"asm": "3045022100e7b3837f2818fe00a05293e0f90e9005d59b0c5c8890f22bd31c36190a9b55e9022027de4b77b78139ea21b9fd30876a447bbf29662bd19d7914028c607bccd772e441 02798913bc057b344de675dac34faafe3dc2f312c758cd9068209f810877306d66",
				"hex": "483045022100e7b3837f2818fe00a05293e0f90e9005d59b0c5c8890f22bd31c36190a9b55e9022027de4b77b78139ea21b9fd30876a447bbf29662bd19d7914028c607bccd772e4412102798913bc057b344de675dac34faafe3dc2f312c758cd9068209f810877306d66"
			},
			"txid": "3c8edde27cb9a9132c22038dac4391496be9db16fd21351565cc1006966fdad5",
			"vout": 114,
			"sequence": 4294967295
		}
	],
	"vout": [
		{
			"value": 0.00001,
			"satoshis": 1000,
			"n": 0,
			"lockingScript": {
				"asm": "OP_DUP OP_HASH160 eb0bd5edba389198e73f8efabddfc61666969ff7 OP_EQUALVERIFY OP_CHECKSIG",
				"hex": "76a914eb0bd5edba389198e73f8efabddfc61666969ff788ac",
				"reqSigs": 1,
				"type": "pubkeyhash"
			}
		}
	]
}

It also adds some new convenience methods to script to get the current type of script as a string and to return all addresses contained within a script (multisig support still TODO).

In the opcodes I updated all raw bytes to use the correct opcode constants to make it easier to read.

@codecov-commenter
Copy link

codecov-commenter commented May 6, 2021

Codecov Report

Merging #23 (e9d1817) into v2 (248cff4) will decrease coverage by 1.60%.
The diff coverage is 65.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##               v2      #23      +/-   ##
==========================================
- Coverage   76.98%   75.37%   -1.61%     
==========================================
  Files          18       18              
  Lines         808      922     +114     
==========================================
+ Hits          622      695      +73     
- Misses        119      149      +30     
- Partials       67       78      +11     
Impacted Files Coverage Δ
bscript/script.go 56.00% <20.00%> (-8.13%) ⬇️
input.go 79.31% <75.00%> (-5.31%) ⬇️
output.go 85.18% <77.14%> (-14.82%) ⬇️
tx.go 80.41% <78.57%> (-0.75%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 248cff4...e9d1817. Read the comment docs.

@theflyingcodr theflyingcodr self-assigned this May 6, 2021
@theflyingcodr theflyingcodr added the enhancement New feature or request label May 6, 2021
jadwahab and others added 3 commits May 7, 2021 10:28
…unmarshallers for input and output so we can unmarshall correctly in the event of the txJSON not having a hex field. We will check this field first however and attempt to map it with hex before falling back to to further unmarshalling process
bscript/script.go Show resolved Hide resolved
tx.go Outdated Show resolved Hide resolved
output.go Outdated Show resolved Hide resolved
tx.go Show resolved Hide resolved
@jadwahab
Copy link
Member

no need to check in the vendor mondules @theflyingcodr

@jadwahab jadwahab merged commit b2889d5 into v2 Jun 1, 2021
@jadwahab jadwahab deleted the tx_json branch June 1, 2021 11:04
@@ -24,6 +25,79 @@ Txout-script / scriptPubKey Script <out-s
type Output struct {
Satoshis uint64
LockingScript *bscript.Script
index int
Copy link
Member

Choose a reason for hiding this comment

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

@theflyingcodr yo i just realised this, don't think this should be in here... do you?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I was using this to track the vout, I'll need to double the code again as it's been a while!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants