mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-09-20 23:18:00 +03:00
outputs/inputs parsing
This commit is contained in:
parent
79fa5743aa
commit
31d4e08224
@ -147,11 +147,19 @@ Can lookup in blockchain as:
|
||||
```
|
||||
=btc -build-file %/lib/btc/hoon
|
||||
=in0 [%32^0x3d6a.f8a8.32b2.ef3f.82f4.dd9c.ccc9.a5af.23db.dbe9.2eae.86f0.7b06.fd41.9525.62b5 62 1 4^0xffff.ffff ~ ~ 10.950.904]
|
||||
=out0 [address=[%bech32 'bc1q59u5epktervh6fxqay2dlph0wxu9hjnx6v8n66'] value=10.944.414]
|
||||
=out0 [script-pubkey=(script-pubkey:btc [%bech32 'bc1q59u5epktervh6fxqay2dlph0wxu9hjnx6v8n66']) value=10.944.414]
|
||||
|
||||
(get-id:txu:btc (encode:txu:btc [~[in0] ~[out0] 0 1]))
|
||||
```
|
||||
|
||||
## TX Decoding/Parsing
|
||||
Signed TX:
|
||||
`01000000000101bee955e95966c35c9b4f1b9b59b8d84b61044b1b6c5d5c380c3b6ed8938c1d6d0000000000ffffffff01385cb01000000000160014ea13bc0f69262d7ab1cb307668105473754b23bc0247304402204c0a3c2aed0d4fc7b6e9b70cc9bd0e489aa82547419ba7a209e5552d6659e2740220158043b25a7342cc231b15eb39217b29decc7d3ca55953f47a0461b3eb0255b2012102b791e56d195e0b597c84d351953176a255019dd5d0ad8b6210fa590d20f45b4c00000000`
|
||||
|
||||
```
|
||||
=inputs 0x1be.e955.e959.66c3.5c9b.4f1b.9b59.b8d8.4b61.044b.1b6c.5d5c.380c.3b6e.d893.8c1d.6d00.0000.0000.ffff.ffff
|
||||
```
|
||||
|
||||
## Unsigned Transactions
|
||||
Using [BIP 143](https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki#P2SHP2WPKH) as a reference.
|
||||
|
||||
|
84
lib/btc.hoon
84
lib/btc.hoon
@ -69,10 +69,76 @@
|
||||
|= o=output:tx
|
||||
^- bytc
|
||||
%- cat:byt
|
||||
:~ (flip:byt 8^value.o)
|
||||
(script-pubkey address.o)
|
||||
~[(flip:byt 8^value.o) script-pubkey.o]
|
||||
--
|
||||
::
|
||||
++ de
|
||||
|%
|
||||
++ nversion
|
||||
|= b=buffer
|
||||
^- [nversion=@ud rest=buffer]
|
||||
:_ (slag 4 b)
|
||||
=< dat
|
||||
%- flip:byt
|
||||
(to-byts:buf (scag 4 b))
|
||||
::
|
||||
++ segwit
|
||||
|= b=buffer
|
||||
^- [segwit=@ud rest=buffer]
|
||||
:_ (slag 2 b)
|
||||
=< dat
|
||||
(to-byts:buf (scag 2 b))
|
||||
:: returns value as 0 since we don't know when we decode
|
||||
::
|
||||
++ input
|
||||
|= b=buffer
|
||||
^- input:tx
|
||||
:* (txid (to-byts:buf (scag 32 b)))
|
||||
=<(dat (flip:byt (to-byts:buf (swag [32 4] b))))
|
||||
(flip:byt (to-byts:buf (swag [37 4] b)))
|
||||
~
|
||||
~
|
||||
0
|
||||
==
|
||||
::
|
||||
++ output
|
||||
|= b=buffer
|
||||
^- output:tx
|
||||
:- (to-byts:buf (slag 8 b))
|
||||
=< dat
|
||||
(flip:byt (to-byts:buf (scag 8 b)))
|
||||
::
|
||||
++ inputs
|
||||
|= b=buffer
|
||||
^- [is=(list input:tx) rest=buffer]
|
||||
=| acc=(list input:tx)
|
||||
=^ count b
|
||||
[(snag 0 b) (slag 1 b)]
|
||||
|-
|
||||
?: =(0 count) [acc b]
|
||||
%= $
|
||||
acc %+ snoc acc
|
||||
(input (scag 41 b))
|
||||
b (slag 41 b)
|
||||
count (dec count)
|
||||
==
|
||||
::
|
||||
++ outputs
|
||||
|= b=buffer
|
||||
^- [os=(list output:tx) rest=buffer]
|
||||
=| acc=(list output:tx)
|
||||
=^ count b
|
||||
[(snag 0 b) (slag 1 b)]
|
||||
|-
|
||||
?: =(0 count) [acc b]
|
||||
%= $
|
||||
acc %+ snoc acc
|
||||
(output (scag 31 b))
|
||||
b (slag 31 b)
|
||||
count (dec count)
|
||||
==
|
||||
--
|
||||
::
|
||||
++ encode
|
||||
|= =data:tx
|
||||
^- bytc
|
||||
@ -92,11 +158,21 @@
|
||||
%- txid
|
||||
%- flip:byt
|
||||
(dsha256 b)
|
||||
++ decode
|
||||
:: TODO: check whether segwit is present by seeing whether the first byte after nversion is 0x0 or not
|
||||
::
|
||||
++ decode-signed
|
||||
|= b=bytc
|
||||
^- data:tx
|
||||
=/ bu=buffer (from-byts:buf b)
|
||||
=^ nversion bu
|
||||
(nversion:de bu)
|
||||
=^ segwit bu
|
||||
(segwit:de bu)
|
||||
=^ inputs bu
|
||||
(inputs:de bu)
|
||||
=^ outputs bu
|
||||
(outputs:de bu)
|
||||
*data:tx
|
||||
:: TODO parse out signatures
|
||||
--
|
||||
:: core to handle BIP174 PSBTs
|
||||
::
|
||||
|
@ -51,14 +51,13 @@
|
||||
+$ input
|
||||
$: =txid
|
||||
pos=@ud
|
||||
witness-ver=@ud
|
||||
sequence=bytc
|
||||
redeem-script=(unit bytc)
|
||||
pubkey=(unit bytc)
|
||||
value=sats
|
||||
==
|
||||
+$ output
|
||||
$: =address
|
||||
$: script-pubkey=bytc
|
||||
value=sats
|
||||
==
|
||||
--
|
||||
|
Loading…
Reference in New Issue
Block a user