summaryrefslogtreecommitdiff
path: root/app/sur/bitcoin.hoon
blob: 4b83b5bf47a521a734007cd998f68fc5e6d0faa6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
::  sur/btc.hoon
::  Utilities for working with BTC data types and transactions
::
::  chyg: whether account is (non-)change. 0 or 1
::  bytc: "btc-byts" with dat cast to @ux
|%
+$  network  ?(%main %testnet %regtest)
+$  hexb  [wid=@ dat=@ux]                :: hex byts
+$  bits  [wid=@ dat=@ub]
+$  xpub  @ta
+$  address
  $%  [%base58 @uc]
      [%bech32 cord]
  ==
+$  fprint  hexb
+$  bipt  $?(%44 %49 %84)
+$  chyg  $?(%0 %1)
+$  idx   @ud
+$  hdkey  [=fprint pubkey=hexb =network =bipt =chyg =idx]
+$  sats  @ud
+$  vbytes  @ud
+$  txid  hexb
+$  utxo  [pos=@ =txid height=@ value=sats recvd=(unit @da)]
++  address-info
  $:  =address
      confirmed-value=sats
      unconfirmed-value=sats
      utxos=(set utxo)
  ==
++  tx
  |%
  +$  data
    $:  is=(list input)
        os=(list output)
        locktime=@ud
        nversion=@ud
        segwit=(unit @ud)
    ==
  +$  val
    $:  =txid
        pos=@ud
        =address
        value=sats
    ==
  ::  included: whether tx is in the mempool or blockchain
  ::
  +$  info
    $:  included=?
        =txid
        confs=@ud
        recvd=(unit @da)
        inputs=(list val)
        outputs=(list val)
    ==
  +$  input
    $:  =txid
        pos=@ud
        sequence=hexb
        script-sig=(unit hexb)
        pubkey=(unit hexb)
        value=sats
    ==
  +$  output
    $:  script-pubkey=hexb
        value=sats
    ==
  --
++  psbt
  |%
  +$  base64  cord
  +$  in  [=utxo rawtx=hexb =hdkey]
  +$  out  [=address hk=(unit hdkey)]
  +$  target  $?(%input %output)
  +$  keyval  [key=hexb val=hexb]
  +$  map  (list keyval)
  --
++  ops
  |%
  ++  op-dup  118
  ++  op-equalverify  136
  ++  op-hash160      169
  ++  op-checksig     172
  --
--