Artifact
56f19c4afdcb7d85421ed29ee4399365a6744906:
- File
squid.fs
— part of check-in
[385b2a8aa4]
at
2019-03-09 12:11:20
on branch trunk
— Markdown edits
(user:
bernd
size: 9146)
0000: 5c 20 6e 65 74 32 6f 20 62 6c 6f 63 6b 20 63 68 \ net2o block ch
0010: 61 69 6e 20 61 6e 64 20 63 72 79 70 74 6f 67 72 ain and cryptogr
0020: 61 70 68 69 63 20 61 73 73 65 74 20 74 72 61 6e aphic asset tran
0030: 73 61 63 74 69 6f 6e 73 0a 0a 5c 20 43 6f 70 79 sactions..\ Copy
0040: 72 69 67 68 74 20 28 43 29 20 32 30 31 37 20 20 right (C) 2017
0050: 20 42 65 72 6e 64 20 50 61 79 73 61 6e 0a 0a 5c Bernd Paysan..\
0060: 20 54 68 69 73 20 70 72 6f 67 72 61 6d 20 69 73 This program is
0070: 20 66 72 65 65 20 73 6f 66 74 77 61 72 65 3a 20 free software:
0080: 79 6f 75 20 63 61 6e 20 72 65 64 69 73 74 72 69 you can redistri
0090: 62 75 74 65 20 69 74 20 61 6e 64 2f 6f 72 20 6d bute it and/or m
00a0: 6f 64 69 66 79 0a 5c 20 69 74 20 75 6e 64 65 72 odify.\ it under
00b0: 20 74 68 65 20 74 65 72 6d 73 20 6f 66 20 74 68 the terms of th
00c0: 65 20 47 4e 55 20 41 66 66 65 72 6f 20 47 65 6e e GNU Affero Gen
00d0: 65 72 61 6c 20 50 75 62 6c 69 63 20 4c 69 63 65 eral Public Lice
00e0: 6e 73 65 20 61 73 20 70 75 62 6c 69 73 68 65 64 nse as published
00f0: 20 62 79 0a 5c 20 74 68 65 20 46 72 65 65 20 53 by.\ the Free S
0100: 6f 66 74 77 61 72 65 20 46 6f 75 6e 64 61 74 69 oftware Foundati
0110: 6f 6e 2c 20 65 69 74 68 65 72 20 76 65 72 73 69 on, either versi
0120: 6f 6e 20 33 20 6f 66 20 74 68 65 20 4c 69 63 65 on 3 of the Lice
0130: 6e 73 65 2c 20 6f 72 0a 5c 20 28 61 74 20 79 6f nse, or.\ (at yo
0140: 75 72 20 6f 70 74 69 6f 6e 29 20 61 6e 79 20 6c ur option) any l
0150: 61 74 65 72 20 76 65 72 73 69 6f 6e 2e 0a 0a 5c ater version...\
0160: 20 54 68 69 73 20 70 72 6f 67 72 61 6d 20 69 73 This program is
0170: 20 64 69 73 74 72 69 62 75 74 65 64 20 69 6e 20 distributed in
0180: 74 68 65 20 68 6f 70 65 20 74 68 61 74 20 69 74 the hope that it
0190: 20 77 69 6c 6c 20 62 65 20 75 73 65 66 75 6c 2c will be useful,
01a0: 0a 5c 20 62 75 74 20 57 49 54 48 4f 55 54 20 41 .\ but WITHOUT A
01b0: 4e 59 20 57 41 52 52 41 4e 54 59 3b 20 77 69 74 NY WARRANTY; wit
01c0: 68 6f 75 74 20 65 76 65 6e 20 74 68 65 20 69 6d hout even the im
01d0: 70 6c 69 65 64 20 77 61 72 72 61 6e 74 79 20 6f plied warranty o
01e0: 66 0a 5c 20 4d 45 52 43 48 41 4e 54 41 42 49 4c f.\ MERCHANTABIL
01f0: 49 54 59 20 6f 72 20 46 49 54 4e 45 53 53 20 46 ITY or FITNESS F
0200: 4f 52 20 41 20 50 41 52 54 49 43 55 4c 41 52 20 OR A PARTICULAR
0210: 50 55 52 50 4f 53 45 2e 20 20 53 65 65 20 74 68 PURPOSE. See th
0220: 65 0a 5c 20 47 4e 55 20 41 66 66 65 72 6f 20 47 e.\ GNU Affero G
0230: 65 6e 65 72 61 6c 20 50 75 62 6c 69 63 20 4c 69 eneral Public Li
0240: 63 65 6e 73 65 20 66 6f 72 20 6d 6f 72 65 20 64 cense for more d
0250: 65 74 61 69 6c 73 2e 0a 0a 5c 20 59 6f 75 20 73 etails...\ You s
0260: 68 6f 75 6c 64 20 68 61 76 65 20 72 65 63 65 69 hould have recei
0270: 76 65 64 20 61 20 63 6f 70 79 20 6f 66 20 74 68 ved a copy of th
0280: 65 20 47 4e 55 20 41 66 66 65 72 6f 20 47 65 6e e GNU Affero Gen
0290: 65 72 61 6c 20 50 75 62 6c 69 63 20 4c 69 63 65 eral Public Lice
02a0: 6e 73 65 0a 5c 20 61 6c 6f 6e 67 20 77 69 74 68 nse.\ along with
02b0: 20 74 68 69 73 20 70 72 6f 67 72 61 6d 2e 20 20 this program.
02c0: 49 66 20 6e 6f 74 2c 20 73 65 65 20 3c 68 74 74 If not, see <htt
02d0: 70 3a 2f 2f 77 77 77 2e 67 6e 75 2e 6f 72 67 2f p://www.gnu.org/
02e0: 6c 69 63 65 6e 73 65 73 2f 3e 2e 0a 0a 5c 20 73 licenses/>...\ s
02f0: 65 61 72 63 68 20 66 6f 72 20 61 20 6b 65 79 20 earch for a key
0300: 77 69 74 68 20 61 20 70 61 72 74 69 63 75 6c 61 with a particula
0310: 72 20 70 75 62 6b 65 79 20 70 72 65 66 69 78 0a r pubkey prefix.
0320: 0a 68 65 72 65 20 6b 61 6c 69 67 6e 20 68 65 72 .here kalign her
0330: 65 20 2d 20 61 6c 6c 6f 74 0a 0a 68 65 72 65 20 e - allot..here
0340: 24 31 34 30 20 65 72 61 73 65 0a 68 65 72 65 20 $140 erase.here
0350: 24 32 30 20 61 6c 6c 6f 74 20 68 65 72 65 20 24 $20 allot here $
0360: 32 30 20 61 6c 6c 6f 74 20 68 65 72 65 20 24 43 20 allot here $C
0370: 30 20 61 6c 6c 6f 74 0a 68 65 72 65 20 24 43 30 0 allot.here $C0
0380: 20 61 6c 6c 6f 74 0a 43 6f 6e 73 74 61 6e 74 20 allot.Constant
0390: 70 6b 74 30 20 43 6f 6e 73 74 61 6e 74 20 62 70 pkt0 Constant bp
03a0: 38 0a 43 6f 6e 73 74 61 6e 74 20 70 6b 30 20 43 8.Constant pk0 C
03b0: 6f 6e 73 74 61 6e 74 20 73 6b 30 0a 0a 3a 20 70 onstant sk0..: p
03c0: 6b 7e 20 28 20 70 6b 20 2d 2d 20 29 20 20 24 31 k~ ( pk -- ) $1
03d0: 46 20 2b 20 64 75 70 20 3e 72 20 63 40 20 24 38 F + dup >r c@ $8
03e0: 30 20 78 6f 72 20 72 3e 20 63 21 20 3b 0a 0a 67 0 xor r> c! ;..g
03f0: 65 32 35 35 31 39 2d 62 61 73 65 70 6f 69 6e 74 e25519-basepoint
0400: 20 62 70 38 20 67 65 32 35 35 31 39 20 6d 6f 76 bp8 ge25519 mov
0410: 65 0a 62 70 38 20 62 70 38 20 62 70 38 20 67 65 e.bp8 bp8 bp8 ge
0420: 32 35 35 31 39 2b 20 5c 20 2a 32 0a 62 70 38 20 25519+ \ *2.bp8
0430: 62 70 38 20 62 70 38 20 67 65 32 35 35 31 39 2b bp8 bp8 ge25519+
0440: 20 5c 20 2a 34 0a 62 70 38 20 62 70 38 20 62 70 \ *4.bp8 bp8 bp
0450: 38 20 67 65 32 35 35 31 39 2b 20 5c 20 2a 38 0a 8 ge25519+ \ *8.
0460: 0a 3a 20 6e 65 78 74 2d 6b 65 79 20 28 20 2d 2d .: next-key ( --
0470: 20 29 0a 20 20 20 20 70 6b 74 30 20 70 6b 74 30 ). pkt0 pkt0
0480: 20 62 70 38 20 67 65 32 35 35 31 39 2b 0a 20 20 bp8 ge25519+.
0490: 20 20 70 6b 30 20 70 6b 74 30 20 67 65 32 35 35 pk0 pkt0 ge255
04a0: 31 39 2d 70 61 63 6b 20 3b 0a 0a 3a 20 73 65 61 19-pack ;..: sea
04b0: 72 63 68 2d 6b 65 79 2d 70 72 65 66 69 78 20 28 rch-key-prefix (
04c0: 20 6c 31 20 6d 61 73 6b 20 2d 2d 20 29 0a 20 20 l1 mask -- ).
04d0: 20 20 73 6b 30 20 67 65 6e 2d 73 6b 20 20 73 6b sk0 gen-sk sk
04e0: 30 20 70 6b 30 20 73 6b 3e 70 6b 0a 20 20 20 20 0 pk0 sk>pk.
04f0: 70 6b 30 20 70 6b 7e 20 20 70 6b 74 30 20 70 6b pk0 pk~ pkt0 pk
0500: 30 20 67 65 32 35 35 31 39 2d 75 6e 70 61 63 6b 0 ge25519-unpack
0510: 2d 20 64 72 6f 70 0a 20 20 20 20 42 45 47 49 4e - drop. BEGIN
0520: 20 20 32 64 75 70 20 70 6b 30 20 62 65 2d 75 6c 2dup pk0 be-ul
0530: 40 20 61 6e 64 20 3c 3e 20 57 48 49 4c 45 20 20 @ and <> WHILE
0540: 6e 65 78 74 2d 6b 65 79 20 38 20 75 3e 36 34 20 next-key 8 u>64
0550: 73 6b 30 20 36 34 2b 21 0a 09 20 20 20 20 6d 73 sk0 64+!.. ms
0560: 67 28 20 64 75 70 20 24 46 46 46 46 20 61 6e 64 g( dup $FFFF and
0570: 20 70 6b 30 20 77 40 20 3d 20 49 46 20 20 27 2e pk0 w@ = IF '.
0580: 27 20 65 6d 69 74 20 20 54 48 45 4e 20 29 0a 20 ' emit THEN ).
0590: 20 20 20 52 45 50 45 41 54 20 32 64 72 6f 70 20 REPEAT 2drop
05a0: 3b 0a 0a 5c 20 77 61 6c 6c 65 74 0a 0a 5c 20 54 ;..\ wallet..\ T
05b0: 68 65 20 73 65 63 72 65 74 20 6b 65 79 20 66 6f he secret key fo
05c0: 72 20 61 20 77 61 6c 6c 65 74 20 69 73 20 6a 75 r a wallet is ju
05d0: 73 74 20 31 32 38 20 62 69 74 73 2c 20 73 6f 20 st 128 bits, so
05e0: 79 6f 75 20 63 61 6e 20 77 72 69 74 65 20 69 74 you can write it
05f0: 20 64 6f 77 6e 0a 5c 20 54 68 65 20 77 61 6c 6c down.\ The wall
0600: 65 74 20 6b 65 79 73 20 61 72 65 20 65 78 74 72 et keys are extr
0610: 61 63 74 65 64 20 66 72 6f 6d 20 74 68 61 74 20 acted from that
0620: 73 65 63 72 65 74 20 6b 65 79 20 74 68 72 6f 75 secret key throu
0630: 67 68 20 6b 65 63 63 61 6b 20 65 78 70 61 6e 73 gh keccak expans
0640: 69 6f 6e 0a 5c 20 53 65 63 72 65 74 20 6b 65 79 ion.\ Secret key
0650: 73 20 67 65 6e 65 72 61 74 65 20 70 75 62 6b 65 s generate pubke
0660: 79 73 2c 20 77 68 69 63 68 20 61 72 65 20 62 69 ys, which are bi
0670: 6e 6e 65 64 20 66 6f 75 6e 64 2d 66 69 72 73 74 nned found-first
0680: 20 69 6e 20 74 68 65 0a 5c 20 6c 65 64 67 65 72 in the.\ ledger
0690: 20 68 79 70 65 72 63 75 62 65 2e 0a 0a 6b 65 63 hypercube...kec
06a0: 63 61 6b 23 20 62 75 66 66 65 72 3a 20 77 61 6c cak# buffer: wal
06b0: 6c 65 74 6b 65 79 0a 24 38 20 56 61 6c 75 65 20 letkey.$8 Value
06c0: 77 61 6c 6c 65 74 73 23 20 5c 20 38 20 77 61 6c wallets# \ 8 wal
06d0: 6c 65 74 20 62 69 74 73 2c 20 64 75 6d 6d 79 20 let bits, dummy
06e0: 76 61 6c 75 65 20 66 6f 72 20 74 65 73 74 69 6e value for testin
06f0: 67 0a 56 61 72 69 61 62 6c 65 20 77 61 6c 6c 65 g.Variable walle
0700: 74 5b 5d 0a 0a 3a 20 3e 77 61 6c 6c 65 74 6b 65 t[]..: >walletke
0710: 79 20 28 20 61 64 64 72 20 75 20 2d 2d 20 29 0a y ( addr u -- ).
0720: 20 20 20 20 32 3e 72 20 36 34 23 30 20 36 34 64 2>r 64#0 64d
0730: 75 70 20 32 72 3e 20 77 61 6c 6c 65 74 6b 65 79 up 2r> walletkey
0740: 20 6b 65 63 63 61 6b 23 20 63 3a 74 77 65 61 6b keccak# c:tweak
0750: 6b 65 79 21 0a 20 20 20 20 77 61 6c 6c 65 74 6b key!. walletk
0760: 65 79 20 63 3a 6b 65 79 21 20 20 63 3a 64 69 66 ey c:key! c:dif
0770: 66 75 73 65 20 3b 0a 3a 20 70 72 6e 67 3e 70 6b fuse ;.: prng>pk
0780: 20 28 20 2d 2d 20 29 0a 20 20 20 20 73 6b 30 20 ( -- ). sk0
0790: 4b 45 59 53 49 5a 45 20 63 3a 70 72 6e 67 0a 20 KEYSIZE c:prng.
07a0: 20 20 20 73 6b 30 20 73 6b 2d 6d 61 73 6b 20 20 sk0 sk-mask
07b0: 73 6b 30 20 70 6b 30 20 73 6b 3e 70 6b 20 3b 0a sk0 pk0 sk>pk ;.
07c0: 3a 20 77 61 6c 6c 65 74 2d 6b 70 5b 5d 21 20 28 : wallet-kp[]! (
07d0: 20 2d 2d 20 66 6c 61 67 20 29 0a 20 20 20 20 70 -- flag ). p
07e0: 6b 30 20 62 65 2d 75 6c 40 20 24 32 30 20 77 61 k0 be-ul@ $20 wa
07f0: 6c 6c 65 74 73 23 20 2d 20 72 73 68 69 66 74 0a llets# - rshift.
0800: 20 20 20 20 64 75 70 20 77 61 6c 6c 65 74 5b 5d dup wallet[]
0810: 20 24 5b 5d 40 20 64 30 3d 20 49 46 20 20 73 6b $[]@ d0= IF sk
0820: 30 20 4b 45 59 53 49 5a 45 32 20 72 6f 74 20 77 0 KEYSIZE2 rot w
0830: 61 6c 6c 65 74 5b 5d 20 24 5b 5d 21 20 74 72 75 allet[] $[]! tru
0840: 65 0a 20 20 20 20 45 4c 53 45 20 20 64 72 6f 70 e. ELSE drop
0850: 20 66 61 6c 73 65 20 20 54 48 45 4e 20 3b 0a 0a false THEN ;..
0860: 3a 20 77 61 6c 6c 65 74 2d 65 78 70 61 6e 64 20 : wallet-expand
0870: 28 20 61 64 64 72 20 75 20 2d 2d 20 29 0a 20 20 ( addr u -- ).
0880: 20 20 5c 47 20 74 61 6b 65 20 61 20 77 61 6c 6c \G take a wall
0890: 65 74 20 6b 65 79 2c 20 61 6e 64 20 65 78 70 61 et key, and expa
08a0: 6e 64 20 69 74 20 74 6f 20 74 68 65 20 70 75 62 nd it to the pub
08b0: 6b 65 79 73 0a 20 20 20 20 63 3a 6b 65 79 40 20 keys. c:key@
08c0: 3e 72 0a 20 20 20 20 3e 77 61 6c 6c 65 74 6b 65 >r. >walletke
08d0: 79 20 20 30 0a 20 20 20 20 42 45 47 49 4e 0a 09 y 0. BEGIN..
08e0: 70 72 6e 67 3e 70 6b 20 77 61 6c 6c 65 74 2d 6b prng>pk wallet-k
08f0: 70 5b 5d 21 20 2d 0a 09 64 75 70 20 31 20 77 61 p[]! -..dup 1 wa
0900: 6c 6c 65 74 73 23 20 6c 73 68 69 66 74 20 75 3e llets# lshift u>
0910: 3d 20 55 4e 54 49 4c 20 20 64 72 6f 70 0a 20 20 = UNTIL drop.
0920: 20 20 72 3e 20 63 3a 6b 65 79 21 20 3b 0a 0a 3a r> c:key! ;..:
0930: 20 2e 77 61 6c 6c 65 74 73 20 28 20 2d 2d 20 29 .wallets ( -- )
0940: 20 5c 47 20 70 72 69 6e 74 20 74 68 65 20 77 61 \G print the wa
0950: 6c 6c 65 74 20 70 75 62 6b 65 79 73 0a 20 20 20 llet pubkeys.
0960: 20 31 20 77 61 6c 6c 65 74 73 23 20 6c 73 68 69 1 wallets# lshi
0970: 66 74 20 30 20 55 2b 44 4f 0a 09 49 20 77 61 6c ft 0 U+DO..I wal
0980: 6c 65 74 5b 5d 20 24 5b 5d 40 20 4b 45 59 53 49 let[] $[]@ KEYSI
0990: 5a 45 20 2f 73 74 72 69 6e 67 20 6f 76 65 72 20 ZE /string over
09a0: 63 40 20 68 65 78 2e 20 73 70 61 63 65 20 38 35 c@ hex. space 85
09b0: 74 79 70 65 20 63 72 0a 20 20 20 20 4c 4f 4f 50 type cr. LOOP
09c0: 20 3b 0a 0a 5c 20 70 61 79 6d 65 6e 74 20 68 61 ;..\ payment ha
09d0: 6e 64 6c 69 6e 67 0a 0a 5c 20 70 61 79 6d 65 6e ndling..\ paymen
09e0: 74 73 20 61 72 65 20 68 61 6e 64 6c 65 64 20 69 ts are handled i
09f0: 6e 20 63 68 61 74 20 6d 65 73 73 61 67 65 73 2e n chat messages.
0a00: 20 20 41 20 70 61 79 6d 65 6e 74 20 69 73 20 65 A payment is e
0a10: 73 73 65 6e 74 69 61 6c 6c 79 0a 5c 20 61 20 64 ssentially.\ a d
0a20: 75 6d 62 20 63 6f 6e 74 72 61 63 74 20 77 69 74 umb contract wit
0a30: 68 20 73 6f 6d 65 20 73 69 6d 70 6c 65 20 66 75 h some simple fu
0a40: 6e 63 74 69 6f 6e 73 3a 0a 5c 0a 5c 20 2a 20 73 nctions:.\.\ * s
0a50: 6f 75 72 63 65 20 63 6f 69 6e 73 20 77 68 69 63 ource coins whic
0a60: 68 20 69 73 20 6f 77 6e 65 64 20 62 79 20 74 68 h is owned by th
0a70: 65 20 73 65 6e 64 65 72 2c 20 77 69 6c 6c 20 62 e sender, will b
0a80: 65 20 74 61 6b 65 6e 20 6f 75 74 20 6f 66 20 74 e taken out of t
0a90: 68 65 20 62 6c 6f 63 6b 20 63 68 61 69 6e 0a 5c he block chain.\
0aa0: 20 2a 20 73 69 6e 6b 20 63 6f 69 6e 73 20 28 6f * sink coins (o
0ab0: 77 6e 65 64 20 62 79 20 73 65 6e 64 65 72 20 6f wned by sender o
0ac0: 72 20 72 65 63 65 69 76 65 72 29 2c 20 77 69 6c r receiver), wil
0ad0: 6c 20 62 65 20 61 64 64 65 64 20 74 6f 20 74 68 l be added to th
0ae0: 65 20 62 6c 6f 63 6b 20 63 68 61 69 6e 0a 5c 0a e block chain.\.
0af0: 5c 20 50 61 79 6d 65 6e 74 73 20 61 72 65 20 61 \ Payments are a
0b00: 74 6f 6d 69 63 20 6f 70 65 72 61 74 69 6f 6e 73 tomic operations
0b10: 3b 20 74 68 65 79 20 63 61 6e 20 69 6e 76 6f 6c ; they can invol
0b20: 76 65 20 6d 6f 72 65 20 74 68 61 6e 20 6f 6e 65 ve more than one
0b30: 20 61 73 73 65 74 0a 5c 20 74 72 61 6e 73 66 65 asset.\ transfe
0b40: 72 2c 20 62 75 74 20 6d 75 73 74 20 62 65 20 65 r, but must be e
0b50: 6d 62 65 64 64 65 64 20 77 69 74 68 69 6e 20 61 mbedded within a
0b60: 20 73 69 67 6e 65 64 20 63 68 61 74 20 6d 65 73 signed chat mes
0b70: 73 61 67 65 2e 0a 5c 0a 5c 20 50 61 79 6d 65 6e sage..\.\ Paymen
0b80: 74 20 6f 66 66 65 72 73 20 61 72 65 20 70 61 72 t offers are par
0b90: 74 69 61 6c 6c 79 2c 20 74 68 65 20 72 65 63 65 tially, the rece
0ba0: 69 76 65 72 20 6e 65 65 64 73 20 74 6f 20 61 64 iver needs to ad
0bb0: 64 20 61 20 73 69 6e 6b 20 63 6f 69 6e 20 74 6f d a sink coin to
0bc0: 20 67 65 74 0a 5c 20 63 6f 6e 74 72 6f 6c 20 6f get.\ control o
0bd0: 76 65 72 20 74 68 65 20 74 72 61 6e 73 66 65 72 ver the transfer
0be0: 72 65 64 20 76 61 6c 75 65 2e 20 20 42 6c 6f 63 red value. Bloc
0bf0: 6b 43 68 61 69 6e 20 70 61 79 6d 65 6e 74 73 20 kChain payments
0c00: 61 72 65 20 66 75 6c 6c 2e 20 20 41 63 74 69 76 are full. Activ
0c10: 65 0a 5c 20 64 61 74 61 20 6f 66 20 61 20 66 75 e.\ data of a fu
0c20: 6c 6c 20 6e 6f 64 65 20 69 73 20 6a 75 73 74 20 ll node is just
0c30: 74 68 65 20 63 6f 69 6e 73 2c 20 6e 6f 74 20 74 the coins, not t
0c40: 68 65 20 63 6f 6e 74 72 61 63 74 73 2e 0a 5c 0a he contracts..\.
0c50: 5c 20 45 78 63 68 61 6e 67 65 20 63 6f 6e 74 72 \ Exchange contr
0c60: 61 63 74 73 20 6d 61 79 20 72 65 71 75 69 72 65 acts may require
0c70: 20 74 68 61 74 20 74 68 65 20 72 65 63 65 69 76 that the receiv
0c80: 65 72 20 61 6c 73 6f 20 6e 65 65 64 73 20 74 6f er also needs to
0c90: 20 61 64 64 20 61 20 73 6f 75 72 63 65 0a 5c 20 add a source.\
0ca0: 63 6f 69 6e 20 6f 66 20 61 20 64 69 66 66 65 72 coin of a differ
0cb0: 65 6e 74 20 61 73 73 65 74 20 74 79 70 65 20 74 ent asset type t
0cc0: 6f 20 6d 61 6b 65 20 74 68 65 20 74 72 61 6e 73 o make the trans
0cd0: 61 63 74 69 6f 6e 20 76 61 6c 69 64 2e 20 20 54 action valid. T
0ce0: 68 65 20 63 6f 6e 74 72 61 63 74 0a 5c 20 69 73 he contract.\ is
0cf0: 20 73 69 67 6e 65 64 20 62 79 20 74 68 65 20 73 signed by the s
0d00: 6f 75 72 63 65 3b 20 68 61 6e 64 65 64 20 69 6e ource; handed in
0d10: 20 62 79 20 74 68 65 20 73 69 6e 6b 2e 20 20 46 by the sink. F
0d20: 6f 72 20 65 61 63 68 20 73 6f 75 72 63 65 2c 20 or each source,
0d30: 74 68 65 72 65 20 6d 75 73 74 0a 5c 20 62 65 20 there must.\ be
0d40: 61 20 63 6f 6e 74 72 61 63 74 20 69 6e 20 74 68 a contract in th
0d50: 65 20 74 72 61 6e 73 61 63 74 69 6f 6e 20 74 6f e transaction to
0d60: 20 62 65 20 76 61 6c 69 64 2e 20 20 41 6c 6c 20 be valid. All
0d70: 73 6f 75 72 63 65 73 20 61 6e 64 20 73 69 6e 6b sources and sink
0d80: 73 20 6d 75 73 74 20 62 65 0a 5c 20 72 65 71 75 s must be.\ requ
0d90: 69 72 65 64 20 62 79 20 61 74 20 6c 65 61 73 74 ired by at least
0da0: 20 6f 6e 65 20 6f 66 20 74 68 65 20 63 6f 6e 74 one of the cont
0db0: 72 61 63 74 73 2e 20 20 41 6c 6c 20 62 61 6c 61 racts. All bala
0dc0: 6e 63 65 73 20 6d 75 73 74 20 6d 61 74 63 68 2e nces must match.
0dd0: 20 20 41 73 73 65 74 73 0a 5c 20 6d 75 73 74 20 Assets.\ must
0de0: 62 65 20 69 6e 20 74 68 65 20 6c 69 73 74 20 6f be in the list o
0df0: 66 20 61 63 63 65 70 74 65 64 20 61 73 73 65 74 f accepted asset
0e00: 73 20 6f 66 20 74 68 65 20 63 68 61 69 6e 2e 0a s of the chain..
0e10: 5c 0a 5c 20 41 20 63 6f 69 6e 20 69 73 20 61 20 \.\ A coin is a
0e20: 31 32 38 20 62 69 74 20 62 69 67 20 65 6e 64 69 128 bit big endi
0e30: 61 6e 20 6e 75 6d 62 65 72 20 66 6f 72 20 74 68 an number for th
0e40: 65 20 76 61 6c 75 65 2c 20 66 6f 6c 6c 6f 77 65 e value, followe
0e50: 64 20 62 79 20 74 68 65 20 61 73 73 65 74 0a 5c d by the asset.\
0e60: 20 74 79 70 65 20 73 74 72 69 6e 67 2c 20 61 6e type string, an
0e70: 64 20 74 68 65 20 73 69 67 6e 61 74 75 72 65 20 d the signature
0e80: 6f 66 20 69 74 73 20 6f 77 6e 65 72 2e 0a 0a 66 of its owner...f
0e90: 61 6c 73 65 20 56 61 6c 75 65 20 73 69 6e 6b 3f alse Value sink?
0ea0: 0a 0a 73 63 6f 70 65 7b 20 6e 65 74 32 6f 2d 62 ..scope{ net2o-b
0eb0: 61 73 65 0a 0a 5c 67 20 0a 5c 67 20 23 23 23 20 ase..\g .\g ###
0ec0: 70 61 79 6d 65 6e 74 20 63 6f 6d 6d 61 6e 64 73 payment commands
0ed0: 20 23 23 23 0a 5c 67 20 0a 0a 63 6d 64 2d 74 61 ###.\g ..cmd-ta
0ee0: 62 6c 65 20 24 40 20 69 6e 68 65 72 69 74 2d 74 ble $@ inherit-t
0ef0: 61 62 6c 65 20 70 61 79 2d 74 61 62 6c 65 0a 0a able pay-table..
0f00: 24 32 30 20 6e 65 74 32 6f 3a 20 70 61 79 2d 73 $20 net2o: pay-s
0f10: 6f 75 72 63 65 20 28 20 24 3a 73 6f 75 72 63 65 ource ( $:source
0f20: 20 2d 2d 20 29 20 5c 67 20 73 6f 75 72 63 65 2c -- ) \g source,
0f30: 20 70 6b 5b 2b 68 61 73 68 5d 20 66 6f 72 20 6c pk[+hash] for l
0f40: 6f 6f 6b 75 70 0a 20 20 20 20 5c 20 65 78 69 73 ookup. \ exis
0f50: 74 69 6e 67 20 73 6f 75 72 63 65 73 20 61 6c 77 ting sources alw
0f60: 61 79 73 20 68 61 64 20 61 20 70 72 65 76 69 6f ays had a previo
0f70: 75 73 20 74 72 61 6e 73 61 63 74 69 6f 6e 0a 20 us transaction.
0f80: 20 20 20 5c 20 6e 65 77 20 73 6f 75 72 63 65 73 \ new sources
0f90: 20 68 61 76 65 20 6f 6e 6c 79 20 61 20 70 6b 20 have only a pk
0fa0: 61 6e 64 20 63 61 6e 20 6f 6e 6c 79 20 62 65 63 and can only bec
0fb0: 6f 6d 65 20 61 20 73 69 6e 6b 0a 20 20 20 20 24 ome a sink. $
0fc0: 3e 20 70 61 79 3a 73 6f 75 72 63 65 20 20 66 61 > pay:source fa
0fd0: 6c 73 65 20 74 6f 20 73 69 6e 6b 3f 20 3b 0a 2b lse to sink? ;.+
0fe0: 6e 65 74 32 6f 3a 20 70 61 79 2d 73 69 6e 6b 20 net2o: pay-sink
0ff0: 28 20 6e 20 24 3a 73 69 67 20 2d 2d 20 29 20 5c ( n $:sig -- ) \
1000: 67 20 73 69 6e 6b 2c 20 73 69 67 6e 61 74 75 72 g sink, signatur
1010: 65 0a 20 20 20 20 5c 20 73 69 6e 6b 20 74 68 61 e. \ sink tha
1020: 74 20 61 6c 72 65 61 64 79 20 65 78 69 73 74 73 t already exists
1030: 20 61 73 20 73 6f 75 72 63 65 20 6e 75 6d 62 65 as source numbe
1040: 72 20 6e 20 69 6e 20 74 68 65 20 63 6f 6e 74 72 r n in the contr
1050: 61 63 74 0a 20 20 20 20 36 34 3e 6e 20 24 3e 20 act. 64>n $>
1060: 70 61 79 3a 73 69 6e 6b 20 20 74 72 75 65 20 74 pay:sink true t
1070: 6f 20 73 69 6e 6b 3f 20 3b 0a 2b 6e 65 74 32 6f o sink? ;.+net2o
1080: 3a 20 70 61 79 2d 61 73 73 65 74 20 28 20 61 73 : pay-asset ( as
1090: 73 65 74 20 2d 2d 20 29 20 5c 67 20 73 65 6c 65 set -- ) \g sele
10a0: 63 74 20 67 6c 6f 62 61 6c 20 61 73 73 65 74 20 ct global asset
10b0: 74 79 70 65 0a 20 20 20 20 36 34 3e 6e 20 70 61 type. 64>n pa
10c0: 79 3a 61 73 73 65 74 20 20 66 61 6c 73 65 20 74 y:asset false t
10d0: 6f 20 73 69 6e 6b 3f 20 3b 0a 2b 6e 65 74 32 6f o sink? ;.+net2o
10e0: 3a 20 70 61 79 2d 6f 62 6c 69 67 61 74 69 6f 6e : pay-obligation
10f0: 20 28 20 24 3a 65 6e 63 2d 61 73 73 65 74 20 2d ( $:enc-asset -
1100: 2d 20 29 20 5c 67 20 73 65 6c 65 63 74 20 70 65 - ) \g select pe
1110: 72 2d 63 6f 6e 74 72 61 63 74 20 6f 62 6c 69 67 r-contract oblig
1120: 61 74 69 6f 6e 0a 20 20 20 20 5c 20 65 6e 63 72 ation. \ encr
1130: 79 70 74 65 64 20 77 69 74 68 20 74 68 65 20 72 ypted with the r
1140: 65 63 65 69 76 65 72 27 73 20 70 75 62 6b 65 79 eceiver's pubkey
1150: 0a 20 20 20 20 24 3e 20 70 61 79 3a 6f 62 6c 69 . $> pay:obli
1160: 67 61 74 69 6f 6e 20 20 66 61 6c 73 65 20 74 6f gation false to
1170: 20 73 69 6e 6b 3f 20 3b 0a 2b 6e 65 74 32 6f 3a sink? ;.+net2o:
1180: 20 70 61 79 2d 61 6d 6f 75 6e 74 20 28 20 36 34 pay-amount ( 64
1190: 61 6d 6f 75 6e 74 20 2d 2d 20 29 20 5c 67 20 61 amount -- ) \g a
11a0: 64 64 2f 73 75 62 74 72 61 63 74 20 61 6d 6f 75 dd/subtract amou
11b0: 6e 74 20 74 6f 20 63 75 72 72 65 6e 74 20 61 73 nt to current as
11c0: 73 65 74 0a 20 20 20 20 36 34 3e 31 32 38 20 70 set. 64>128 p
11d0: 61 79 3a 61 6d 6f 75 6e 74 20 20 66 61 6c 73 65 ay:amount false
11e0: 20 74 6f 20 73 69 6e 6b 3f 20 3b 0a 2b 6e 65 74 to sink? ;.+net
11f0: 32 6f 3a 20 70 61 79 2d 64 61 6d 6f 75 6e 74 20 2o: pay-damount
1200: 28 20 31 32 38 61 6d 6f 75 6e 74 20 2d 2d 20 29 ( 128amount -- )
1210: 20 5c 67 20 61 64 64 2f 73 75 62 74 72 61 63 74 \g add/subtract
1220: 20 31 32 38 20 62 69 74 20 61 6d 6f 75 6e 74 0a 128 bit amount.
1230: 20 20 20 20 70 61 79 3a 61 6d 6f 75 6e 74 20 20 pay:amount
1240: 66 61 6c 73 65 20 74 6f 20 73 69 6e 6b 3f 20 3b false to sink? ;
1250: 0a 2b 6e 65 74 32 6f 3a 20 70 61 79 2d 63 6f 6d .+net2o: pay-com
1260: 6d 65 6e 74 20 28 20 24 3a 65 6e 63 2d 63 6f 6d ment ( $:enc-com
1270: 6d 65 6e 74 20 2d 2d 20 29 20 5c 67 20 63 6f 6d ment -- ) \g com
1280: 6d 65 6e 74 2c 20 65 6e 63 72 79 70 74 65 64 20 ment, encrypted
1290: 66 6f 72 20 73 65 6c 65 63 74 65 64 20 6b 65 79 for selected key
12a0: 0a 20 20 20 20 24 3e 20 70 61 79 3a 63 6f 6d 6d . $> pay:comm
12b0: 65 6e 74 20 20 66 61 6c 73 65 20 74 6f 20 73 69 ent false to si
12c0: 6e 6b 3f 20 3b 0a 2b 6e 65 74 32 6f 3a 20 70 61 nk? ;.+net2o: pa
12d0: 79 2d 62 61 6c 61 6e 63 65 20 28 20 75 20 2d 2d y-balance ( u --
12e0: 20 29 20 5c 67 20 73 65 6c 65 63 74 26 62 61 6c ) \g select&bal
12f0: 61 6e 63 65 20 61 73 73 65 74 0a 20 20 20 20 5c ance asset. \
1300: 20 61 20 62 61 6c 61 6e 63 65 20 6d 6f 64 69 66 a balance modif
1310: 69 65 73 20 74 68 65 20 61 73 73 65 74 20 6f 66 ies the asset of
1320: 20 74 68 65 20 63 75 72 72 65 6e 74 20 61 63 74 the current act
1330: 69 76 65 20 73 6f 75 72 63 65 0a 20 20 20 20 36 ive source. 6
1340: 34 3e 6e 20 70 61 79 3a 62 61 6c 61 6e 63 65 20 4>n pay:balance
1350: 20 66 61 6c 73 65 20 74 6f 20 73 69 6e 6b 3f 20 false to sink?
1360: 3b 0a 2b 6e 65 74 32 6f 3a 20 70 61 79 2d 23 73 ;.+net2o: pay-#s
1370: 6f 75 72 63 65 20 28 20 75 20 2d 2d 20 29 20 5c ource ( u -- ) \
1380: 67 20 73 65 6c 65 63 74 20 73 6f 75 72 63 65 0a g select source.
1390: 20 20 20 20 36 34 3e 6e 20 70 61 79 3a 23 73 6f 64>n pay:#so
13a0: 75 72 63 65 20 20 66 61 6c 73 65 20 74 6f 20 73 urce false to s
13b0: 69 6e 6b 3f 20 3b 0a 0a 70 61 79 2d 74 61 62 6c ink? ;..pay-tabl
13c0: 65 20 24 73 61 76 65 0a 0a 7d 73 63 6f 70 65 0a e $save..}scope.
13d0: 0a 5c 67 20 0a 5c 67 20 23 23 23 20 43 6f 6e 74 .\g .\g ### Cont
13e0: 72 61 63 74 73 20 23 23 23 0a 5c 67 20 0a 5c 67 racts ###.\g .\g
13f0: 20 43 6f 6e 74 72 61 63 74 73 20 61 72 65 20 73 Contracts are s
1400: 74 61 74 65 20 63 68 61 6e 67 65 73 20 74 6f 20 tate changes to
1410: 77 61 6c 6c 65 74 73 2e 20 20 41 20 73 65 72 69 wallets. A seri
1420: 61 6c 69 7a 65 64 20 77 61 6c 6c 65 74 20 69 73 alized wallet is
1430: 20 61 20 63 6f 6e 74 72 61 63 74 0a 5c 67 20 74 a contract.\g t
1440: 68 61 74 20 63 6f 6e 74 61 69 6e 73 20 61 6c 6c hat contains all
1450: 20 74 68 65 20 63 68 61 6e 67 65 73 20 66 72 6f the changes fro
1460: 6d 20 61 6e 20 65 6d 70 74 79 20 77 61 6c 6c 65 m an empty walle
1470: 74 20 74 6f 20 66 69 6c 6c 20 69 74 3b 20 69 74 t to fill it; it
1480: 20 69 73 20 6e 6f 74 0a 5c 67 20 63 68 65 63 6b is not.\g check
1490: 65 64 20 66 6f 72 20 62 61 6c 61 6e 63 65 2e 0a ed for balance..
14a0: 5c 67 20 0a 5c 67 20 41 20 64 75 6d 62 20 63 6f \g .\g A dumb co
14b0: 6e 74 72 61 63 74 20 69 73 20 63 68 65 63 6b 65 ntract is checke
14c0: 64 20 66 6f 72 20 62 61 6c 61 6e 63 65 2e 20 20 d for balance.
14d0: 49 74 20 63 6f 6e 73 69 73 74 73 20 6f 66 20 73 It consists of s
14e0: 65 76 65 72 61 6c 20 73 65 6c 65 63 74 6f 72 73 everal selectors
14f0: 0a 5c 67 20 28 73 6f 75 72 63 65 2f 61 63 63 6f .\g (source/acco
1500: 75 6e 74 2c 20 61 73 73 65 74 29 2c 20 74 72 61 unt, asset), tra
1510: 6e 73 61 63 74 69 6f 6e 73 20 28 61 6d 6f 75 6e nsactions (amoun
1520: 74 73 20 61 64 64 65 64 20 6f 72 20 73 75 62 74 ts added or subt
1530: 72 61 63 74 65 64 20 66 72 6f 6d 20 61 6e 0a 5c racted from an.\
1540: 67 20 61 73 73 65 74 29 2c 20 63 6f 6d 6d 65 6e g asset), commen
1550: 74 73 20 28 65 6e 63 6f 64 65 64 20 66 6f 72 20 ts (encoded for
1560: 74 68 65 20 72 65 63 65 69 76 65 72 2c 20 77 69 the receiver, wi
1570: 74 68 20 61 20 65 70 68 65 72 6d 65 72 61 6c 20 th a ephermeral
1580: 70 75 62 6b 65 79 20 61 73 0a 5c 67 20 73 74 61 pubkey as.\g sta
1590: 72 74 20 61 6e 64 20 61 20 48 4d 41 43 20 61 73 rt and a HMAC as
15a0: 20 65 6e 64 29 2e 20 43 6f 6d 6d 65 6e 74 73 20 end). Comments
15b0: 61 72 65 20 66 69 78 65 64 20 36 34 20 62 79 74 are fixed 64 byt
15c0: 65 73 2c 20 65 69 74 68 65 72 20 70 6c 61 69 6e es, either plain
15d0: 20 74 65 78 74 20 6f 72 0a 5c 67 20 68 61 73 68 text or.\g hash
15e0: 65 73 20 74 6f 20 66 69 6c 65 73 2e 20 20 54 72 es to files. Tr
15f0: 61 6e 73 61 63 74 69 6f 6e 73 20 68 61 76 65 20 ansactions have
1600: 74 6f 20 62 61 6c 61 6e 63 65 2c 20 77 68 69 63 to balance, whic
1610: 68 20 69 73 20 66 61 63 69 6c 69 74 61 74 65 64 h is facilitated
1620: 20 77 69 74 68 0a 5c 67 20 74 68 65 20 62 61 6c with.\g the bal
1630: 61 6e 63 65 20 63 6f 6d 6d 61 6e 64 2c 20 77 68 ance command, wh
1640: 69 63 68 20 62 61 6c 61 6e 63 65 73 20 74 68 65 ich balances the
1650: 20 73 65 6c 65 63 74 65 64 20 61 73 73 65 74 2e selected asset.
1660: 0a 5c 67 20 0a 5c 67 20 54 68 65 20 73 69 67 6e .\g .\g The sign
1670: 61 74 75 72 65 20 6f 66 20 61 20 63 6f 6e 74 72 ature of a contr
1680: 61 63 74 20 73 69 67 6e 73 20 74 68 65 20 77 61 act signs the wa
1690: 6c 6c 65 74 27 73 20 73 74 61 74 65 20 28 73 65 llet's state (se
16a0: 72 69 61 6c 69 7a 65 64 20 69 6e 0a 5c 67 20 6e rialized in.\g n
16b0: 6f 72 6d 61 6c 69 7a 65 64 20 66 6f 72 6d 29 20 ormalized form)
16c0: 61 66 74 65 72 20 74 68 65 20 63 6f 6e 74 72 61 after the contra
16d0: 63 74 20 68 61 73 20 62 65 65 6e 20 65 78 65 63 ct has been exec
16e0: 75 74 65 64 2e 20 20 54 68 65 20 63 75 72 72 65 uted. The curre
16f0: 6e 74 0a 5c 67 20 63 6f 6e 74 72 61 63 74 27 73 nt.\g contract's
1700: 20 68 61 73 68 20 69 73 20 70 61 72 74 20 6f 66 hash is part of
1710: 20 74 68 65 20 73 65 72 69 61 6c 69 7a 61 74 69 the serializati
1720: 6f 6e 2e 0a 0a 56 61 72 69 61 62 6c 65 20 53 77 on...Variable Sw
1730: 61 70 44 72 61 67 6f 6e 43 68 61 69 6e 23 20 28 apDragonChain# (
1740: 20 22 68 61 73 68 22 20 2d 2d 20 22 63 6f 6e 74 "hash" -- "cont
1750: 72 61 63 74 22 20 29 0a 56 61 72 69 61 62 6c 65 ract" ).Variable
1760: 20 53 77 61 70 44 72 61 67 6f 6e 4b 65 79 73 23 SwapDragonKeys#
1770: 20 20 28 20 22 70 6b 22 20 2d 2d 20 22 68 61 73 ( "pk" -- "has
1780: 68 2b 5b 61 73 73 65 74 2c 61 6d 6f 75 6e 74 5d h+[asset,amount]
1790: 2a 22 20 29 0a 5c 20 55 70 64 61 74 65 73 20 67 *" ).\ Updates g
17a0: 6f 20 74 6f 20 53 77 61 70 44 72 61 67 6f 6e 4b o to SwapDragonK
17b0: 65 79 73 27 23 3b 20 6f 6e 6c 79 20 6f 6e 65 20 eys'#; only one
17c0: 74 72 61 6e 73 61 63 74 69 6f 6e 20 70 65 72 20 transaction per
17d0: 70 6b 26 63 79 63 6c 65 21 0a 56 61 72 69 61 62 pk&cycle!.Variab
17e0: 6c 65 20 53 77 61 70 44 72 61 67 6f 6e 4b 65 79 le SwapDragonKey
17f0: 73 27 23 20 20 28 20 22 70 6b 22 20 2d 2d 20 22 s'# ( "pk" -- "
1800: 68 61 73 68 2b 5b 61 73 73 65 74 2c 61 6d 6f 75 hash+[asset,amou
1810: 6e 74 5d 2a 22 20 29 0a 56 61 72 69 61 62 6c 65 nt]*" ).Variable
1820: 20 24 53 77 61 70 41 73 73 65 74 73 5b 5d 20 28 $SwapAssets[] (
1830: 20 6e 20 2d 2d 20 61 73 73 65 74 20 75 20 29 0a n -- asset u ).
1840: 0a 73 63 6f 70 65 7b 20 70 61 79 0a 24 31 30 20 .scope{ pay.$10
1850: 62 75 66 66 65 72 3a 20 62 61 6c 61 6e 63 65 30 buffer: balance0
1860: 0a 24 31 30 20 63 65 6c 6c 2b 20 62 75 66 66 65 .$10 cell+ buffe
1870: 72 3a 20 6e 65 77 2d 61 73 73 65 74 0a 0a 3a 6e r: new-asset..:n
1880: 6f 6e 61 6d 65 20 7b 20 64 3a 20 70 6b 20 2d 2d oname { d: pk --
1890: 20 7d 20 5c 20 70 6b 5b 2b 68 61 73 68 5d 0a 20 } \ pk[+hash].
18a0: 20 20 20 70 6b 20 64 75 70 20 6b 65 79 73 69 7a pk dup keysiz
18b0: 65 20 3d 20 49 46 20 20 5b 3a 20 74 79 70 65 20 e = IF [: type
18c0: 6b 65 79 73 69 7a 65 20 73 70 61 63 65 73 20 3b keysize spaces ;
18d0: 5d 20 24 74 6d 70 20 20 54 48 45 4e 0a 20 20 20 ] $tmp THEN.
18e0: 20 73 6f 75 72 63 65 73 5b 5d 20 64 75 70 20 24 sources[] dup $
18f0: 5b 5d 23 20 74 6f 20 63 75 72 72 65 6e 74 2d 70 []# to current-p
1900: 6b 20 24 2b 5b 5d 21 0a 20 20 20 20 70 6b 20 6b k $+[]!. pk k
1910: 65 79 7c 20 53 77 61 70 44 72 61 67 6f 6e 4b 65 ey| SwapDragonKe
1920: 79 73 23 20 23 40 0a 20 20 20 20 32 64 75 70 20 ys# #@. 2dup
1930: 64 30 3c 3e 20 49 46 0a 09 70 6b 20 6b 65 79 73 d0<> IF..pk keys
1940: 69 7a 65 20 2f 73 74 72 69 6e 67 20 32 6f 76 65 ize /string 2ove
1950: 72 20 6b 65 79 7c 20 73 74 72 3d 20 30 3d 20 21 r key| str= 0= !
1960: 21 73 71 75 69 64 2d 68 61 73 68 21 21 0a 09 6b !squid-hash!!..k
1970: 65 79 73 69 7a 65 20 2f 73 74 72 69 6e 67 0a 20 eysize /string.
1980: 20 20 20 54 48 45 4e 0a 20 20 20 20 63 75 72 72 THEN. curr
1990: 65 6e 74 2d 70 6b 20 61 73 73 65 74 73 5b 5d 20 ent-pk assets[]
19a0: 24 5b 5d 21 0a 3b 20 70 61 79 2d 63 6c 61 73 73 $[]!.; pay-class
19b0: 20 69 73 20 73 6f 75 72 63 65 0a 0a 3a 20 3f 64 is source..: ?d
19c0: 6f 75 62 6c 65 2d 74 72 61 6e 73 61 63 74 69 6f ouble-transactio
19d0: 6e 20 28 20 68 61 73 68 20 75 20 70 6b 20 75 20 n ( hash u pk u
19e0: 2d 2d 20 68 61 73 68 20 75 20 29 0a 20 20 20 20 -- hash u ).
19f0: 20 53 77 61 70 44 72 61 67 6f 6e 4b 65 79 73 27 SwapDragonKeys'
1a00: 23 20 23 40 20 32 64 75 70 20 64 30 3d 20 49 46 # #@ 2dup d0= IF
1a10: 0a 09 32 64 72 6f 70 0a 20 20 20 20 45 4c 53 45 ..2drop. ELSE
1a20: 20 5c 20 79 6f 75 20 63 61 6e 20 63 68 65 63 6b \ you can check
1a30: 20 74 68 65 20 73 61 6d 65 20 74 72 61 6e 73 61 the same transa
1a40: 63 74 69 6f 6e 20 74 77 69 63 65 0a 09 32 6f 76 ction twice..2ov
1a50: 65 72 20 73 74 72 3d 20 30 3d 20 21 21 64 6f 75 er str= 0= !!dou
1a60: 62 6c 65 2d 74 72 61 6e 73 61 63 74 69 6f 6e 21 ble-transaction!
1a70: 21 0a 20 20 20 20 54 48 45 4e 20 3b 0a 0a 3a 6e !. THEN ;..:n
1a80: 6f 6e 61 6d 65 20 28 20 6e 20 2d 2d 20 29 0a 20 oname ( n -- ).
1a90: 20 20 20 64 75 70 20 73 6f 75 72 63 65 73 5b 5d dup sources[]
1aa0: 20 24 5b 5d 23 20 75 3e 3d 20 21 21 69 6e 76 2d $[]# u>= !!inv-
1ab0: 69 6e 64 65 78 21 21 20 74 6f 20 63 75 72 72 65 index!! to curre
1ac0: 6e 74 2d 70 6b 0a 3b 20 70 61 79 2d 63 6c 61 73 nt-pk.; pay-clas
1ad0: 73 20 69 73 20 23 73 6f 75 72 63 65 0a 0a 3a 6e s is #source..:n
1ae0: 6f 6e 61 6d 65 20 28 20 6e 20 61 64 64 72 20 75 oname ( n addr u
1af0: 20 2d 2d 20 29 0a 20 20 20 20 72 6f 74 20 23 73 -- ). rot #s
1b00: 6f 75 72 63 65 0a 20 20 20 20 73 69 67 73 69 7a ource. sigsiz
1b10: 65 23 20 3c 3e 20 21 21 6e 6f 2d 73 69 67 21 21 e# <> !!no-sig!!
1b20: 20 7b 20 73 69 67 20 7d 0a 20 20 20 20 63 6d 64 { sig }. cmd
1b30: 62 75 66 24 20 6f 76 65 72 20 2b 20 73 69 67 20 buf$ over + sig
1b40: 75 6d 69 6e 20 6f 76 65 72 20 75 6d 61 78 20 6f umin over umax o
1b50: 76 65 72 20 2d 20 32 20 2d 20 5c 20 63 6d 64 62 ver - 2 - \ cmdb
1b60: 75 66 20 75 70 20 74 6f 20 74 68 65 20 73 69 67 uf up to the sig
1b70: 20 73 74 72 69 6e 67 0a 20 20 20 20 63 3a 30 6b string. c:0k
1b80: 65 79 20 32 64 75 70 20 63 3a 68 61 73 68 0a 20 ey 2dup c:hash.
1b90: 20 20 20 63 75 72 72 65 6e 74 2d 70 6b 20 73 6f current-pk so
1ba0: 75 72 63 65 73 5b 5d 20 24 5b 5d 40 20 64 75 70 urces[] $[]@ dup
1bb0: 20 30 3d 20 21 21 73 69 6e 6b 2d 63 6c 65 61 72 0= !!sink-clear
1bc0: 65 64 21 21 20 7b 20 64 3a 20 70 6b 2b 68 61 73 ed!! { d: pk+has
1bd0: 68 20 7d 0a 20 20 20 20 70 6b 2b 68 61 73 68 20 h }. pk+hash
1be0: 6b 65 79 73 69 7a 65 20 2f 73 74 72 69 6e 67 0a keysize /string.
1bf0: 20 20 20 20 32 64 75 70 20 63 3a 68 61 73 68 40 2dup c:hash@
1c00: 20 53 77 61 70 44 72 61 67 6f 6e 43 68 61 69 6e SwapDragonChain
1c10: 23 20 23 21 0a 20 20 20 20 21 21 46 49 58 4d 45 # #!. !!FIXME
1c20: 21 21 0a 20 20 20 20 5c 20 6d 69 73 73 69 6e 67 !!. \ missing
1c30: 20 68 65 72 65 3a 20 6e 6f 72 6d 61 6c 69 7a 65 here: normalize
1c40: 20 74 68 65 20 73 69 6e 6b 27 73 20 61 63 63 6f the sink's acco
1c50: 75 6e 74 2c 20 61 6e 64 20 63 61 6c 63 75 6c 61 unt, and calcula
1c60: 74 65 20 61 20 68 61 73 68 20 6f 76 65 72 20 74 te a hash over t
1c70: 68 61 74 0a 20 20 20 20 73 69 67 20 73 69 67 73 hat. sig sigs
1c80: 69 7a 65 23 20 70 6b 2b 68 61 73 68 20 64 72 6f ize# pk+hash dro
1c90: 70 20 70 6b 2d 73 69 67 3f 20 21 21 73 69 67 21 p pk-sig? !!sig!
1ca0: 21 20 32 64 72 6f 70 0a 20 20 20 20 5b 3a 20 20 ! 2drop. [:
1cb0: 63 75 72 72 65 6e 74 2d 70 6b 20 73 6f 75 72 63 current-pk sourc
1cc0: 65 73 5b 5d 20 24 5b 5d 40 20 6b 65 79 73 69 7a es[] $[]@ keysiz
1cd0: 65 20 2f 73 74 72 69 6e 67 20 74 79 70 65 0a 09 e /string type..
1ce0: 63 75 72 72 65 6e 74 2d 70 6b 20 61 73 73 65 74 current-pk asset
1cf0: 73 5b 5d 20 20 24 5b 5d 40 20 74 79 70 65 20 3b s[] $[]@ type ;
1d00: 5d 20 24 74 6d 70 0a 20 20 20 20 70 6b 2b 68 61 ] $tmp. pk+ha
1d10: 73 68 20 6b 65 79 7c 20 3f 64 6f 75 62 6c 65 2d sh key| ?double-
1d20: 74 72 61 6e 73 61 63 74 69 6f 6e 0a 20 20 20 20 transaction.
1d30: 70 6b 2b 68 61 73 68 20 6b 65 79 7c 20 53 77 61 pk+hash key| Swa
1d40: 70 44 72 61 67 6f 6e 4b 65 79 73 27 23 20 23 21 pDragonKeys'# #!
1d50: 0a 20 20 20 20 63 75 72 72 65 6e 74 2d 70 6b 20 . current-pk
1d60: 73 6f 75 72 63 65 73 5b 5d 20 24 5b 5d 66 72 65 sources[] $[]fre
1d70: 65 0a 3b 20 70 61 79 2d 63 6c 61 73 73 20 69 73 e.; pay-class is
1d80: 20 73 69 6e 6b 0a 0a 3a 6e 6f 6e 61 6d 65 20 28 sink..:noname (
1d90: 20 6e 20 2d 2d 20 29 0a 20 20 20 20 64 75 70 20 n -- ). dup
1da0: 24 53 77 61 70 41 73 73 65 74 73 5b 5d 20 24 5b $SwapAssets[] $[
1db0: 5d 23 20 75 3e 3d 20 21 21 69 6e 76 2d 69 6e 64 ]# u>= !!inv-ind
1dc0: 65 78 21 21 0a 20 20 20 20 74 6f 20 63 75 72 72 ex!!. to curr
1dd0: 65 6e 74 2d 61 73 73 65 74 0a 20 20 20 20 63 75 ent-asset. cu
1de0: 72 72 65 6e 74 2d 61 73 73 65 74 20 62 61 6c 61 rrent-asset bala
1df0: 6e 63 65 73 5b 5d 20 24 5b 5d 40 20 6e 69 70 20 nces[] $[]@ nip
1e00: 30 3d 20 49 46 0a 09 62 61 6c 61 6e 63 65 30 20 0= IF..balance0
1e10: 24 31 30 20 63 75 72 72 65 6e 74 2d 61 73 73 65 $10 current-asse
1e20: 74 20 62 61 6c 61 6e 63 65 73 5b 5d 20 24 5b 5d t balances[] $[]
1e30: 21 0a 20 20 20 20 54 48 45 4e 0a 3b 20 70 61 79 !. THEN.; pay
1e40: 2d 63 6c 61 73 73 20 69 73 20 61 73 73 65 74 0a -class is asset.
1e50: 0a 3a 20 31 32 38 2b 21 3f 20 28 20 31 32 38 78 .: 128+!? ( 128x
1e60: 20 61 64 64 72 20 2d 2d 20 66 6c 61 67 20 29 0a addr -- flag ).
1e70: 20 20 20 20 64 75 70 20 3e 72 20 31 32 38 40 20 dup >r 128@
1e80: 31 32 38 2b 20 72 3e 20 6f 76 65 72 20 3e 72 20 128+ r> over >r
1e90: 31 32 38 21 20 72 3e 20 30 3c 20 3b 0a 0a 3a 6e 128! r> 0< ;..:n
1ea0: 6f 6e 61 6d 65 20 28 20 31 32 38 61 73 73 65 74 oname ( 128asset
1eb0: 20 2d 2d 20 29 0a 20 20 20 20 36 34 6f 76 65 72 -- ). 64over
1ec0: 20 36 34 6f 76 65 72 20 63 75 72 72 65 6e 74 2d 64over current-
1ed0: 61 73 73 65 74 20 62 61 6c 61 6e 63 65 73 5b 5d asset balances[]
1ee0: 20 24 5b 5d 40 20 64 72 6f 70 20 31 32 38 2b 21 $[]@ drop 128+!
1ef0: 3f 20 64 72 6f 70 0a 20 20 20 20 63 75 72 72 65 ? drop. curre
1f00: 6e 74 2d 70 6b 20 61 73 73 65 74 73 5b 5d 20 24 nt-pk assets[] $
1f10: 5b 5d 40 20 62 6f 75 6e 64 73 20 55 2b 44 4f 0a []@ bounds U+DO.
1f20: 09 49 20 40 20 63 75 72 72 65 6e 74 2d 61 73 73 .I @ current-ass
1f30: 65 74 20 3d 20 49 46 20 20 49 20 63 65 6c 6c 2b et = IF I cell+
1f40: 20 31 32 38 2b 21 3f 20 21 21 69 6e 73 75 66 66 128+!? !!insuff
1f50: 69 63 69 65 6e 74 2d 61 73 73 65 74 21 21 0a 09 icient-asset!!..
1f60: 20 20 20 20 55 4e 4c 4f 4f 50 20 20 45 58 49 54 UNLOOP EXIT
1f70: 20 20 54 48 45 4e 0a 20 20 20 20 24 31 30 20 63 THEN. $10 c
1f80: 65 6c 6c 2b 20 2b 4c 4f 4f 50 0a 20 20 20 20 64 ell+ +LOOP. d
1f90: 75 70 20 30 3c 20 21 21 69 6e 73 75 66 66 69 63 up 0< !!insuffic
1fa0: 69 65 6e 74 2d 61 73 73 65 74 21 21 0a 20 20 20 ient-asset!!.
1fb0: 20 63 75 72 72 65 6e 74 2d 61 73 73 65 74 20 6e current-asset n
1fc0: 65 77 2d 61 73 73 65 74 20 21 20 20 6e 65 77 2d ew-asset ! new-
1fd0: 61 73 73 65 74 20 63 65 6c 6c 2b 20 31 32 38 21 asset cell+ 128!
1fe0: 0a 20 20 20 20 6e 65 77 2d 61 73 73 65 74 20 24 . new-asset $
1ff0: 31 30 20 63 65 6c 6c 2b 20 63 75 72 72 65 6e 74 10 cell+ current
2000: 2d 70 6b 20 61 73 73 65 74 73 5b 5d 20 24 5b 5d -pk assets[] $[]
2010: 2b 21 0a 3b 20 70 61 79 2d 63 6c 61 73 73 20 69 +!.; pay-class i
2020: 73 20 61 6d 6f 75 6e 74 0a 0a 3a 6e 6f 6e 61 6d s amount..:nonam
2030: 65 20 28 20 6e 20 2d 2d 20 29 20 61 73 73 65 74 e ( n -- ) asset
2040: 0a 20 20 20 20 36 34 23 30 20 36 34 64 75 70 20 . 64#0 64dup
2050: 63 75 72 72 65 6e 74 2d 61 73 73 65 74 20 62 61 current-asset ba
2060: 6c 61 6e 63 65 73 5b 5d 20 24 5b 5d 40 20 64 72 lances[] $[]@ dr
2070: 6f 70 20 31 32 38 40 20 31 32 38 2d 20 5c 20 6a op 128@ 128- \ j
2080: 75 73 74 20 61 20 31 32 38 6e 65 67 61 74 65 0a ust a 128negate.
2090: 20 20 20 20 61 6d 6f 75 6e 74 0a 3b 20 70 61 79 amount.; pay
20a0: 2d 63 6c 61 73 73 20 69 73 20 62 61 6c 61 6e 63 -class is balanc
20b0: 65 0a 0a 3a 6e 6f 6e 61 6d 65 20 28 20 2d 2d 20 e..:noname ( --
20c0: 29 20 20 73 69 6e 6b 3f 20 69 6e 76 65 72 74 20 ) sink? invert
20d0: 21 21 6e 6f 74 2d 73 75 6e 6b 21 21 0a 20 20 20 !!not-sunk!!.
20e0: 20 62 61 6c 61 6e 63 65 73 5b 5d 20 24 5b 5d 23 balances[] $[]#
20f0: 20 30 20 3f 44 4f 0a 09 49 20 62 61 6c 61 6e 63 0 ?DO..I balanc
2100: 65 73 5b 5d 20 24 5b 5d 40 20 62 61 6c 61 6e 63 es[] $[]@ balanc
2110: 65 30 20 6f 76 65 72 20 73 74 72 3d 20 30 3d 20 e0 over str= 0=
2120: 21 21 6e 6f 74 2d 62 61 6c 61 6e 63 65 64 21 21 !!not-balanced!!
2130: 0a 20 20 20 20 4c 4f 4f 50 0a 20 20 20 20 73 6f . LOOP. so
2140: 75 72 63 65 73 5b 5d 20 24 5b 5d 23 20 30 20 3f urces[] $[]# 0 ?
2150: 44 4f 0a 09 49 20 73 6f 75 72 63 65 73 5b 5d 20 DO..I sources[]
2160: 24 5b 5d 40 20 6e 69 70 20 21 21 6e 6f 74 2d 73 $[]@ nip !!not-s
2170: 75 6e 6b 21 21 0a 20 20 20 20 4c 4f 4f 50 0a 3b unk!!. LOOP.;
2180: 20 70 61 79 2d 63 6c 61 73 73 20 69 73 20 66 69 pay-class is fi
2190: 6e 61 6c 69 7a 65 0a 0a 3a 20 75 70 64 61 74 65 nalize..: update
21a0: 20 28 20 2d 2d 20 29 0a 20 20 20 20 53 77 61 70 ( -- ). Swap
21b0: 44 72 61 67 6f 6e 4b 65 79 73 27 23 0a 20 20 20 DragonKeys'#.
21c0: 20 5b 3a 20 28 20 6c 61 73 74 20 2d 2d 20 29 20 [: ( last -- )
21d0: 3e 72 20 72 40 20 63 65 6c 6c 2b 20 24 40 20 72 >r r@ cell+ $@ r
21e0: 40 20 24 40 20 53 77 61 70 44 72 61 67 6f 6e 4b @ $@ SwapDragonK
21f0: 65 79 73 23 20 23 21 20 3b 5d 20 23 6d 61 70 0a eys# #! ;] #map.
2200: 20 20 20 20 53 77 61 70 44 72 61 67 6f 6e 4b 65 SwapDragonKe
2210: 79 73 27 23 20 23 66 72 65 65 73 20 3b 0a 7d 73 ys'# #frees ;.}s
2220: 63 6f 70 65 0a 0a 5c 5c 5c 0a 4c 6f 63 61 6c 20 cope..\\\.Local
2230: 56 61 72 69 61 62 6c 65 73 3a 0a 66 6f 72 74 68 Variables:.forth
2240: 2d 6c 6f 63 61 6c 2d 77 6f 72 64 73 3a 0a 20 20 -local-words:.
2250: 20 20 28 0a 20 20 20 20 20 28 28 22 6e 65 74 32 (. (("net2
2260: 6f 3a 22 20 22 2b 6e 65 74 32 6f 3a 22 29 20 64 o:" "+net2o:") d
2270: 65 66 69 6e 69 74 69 6f 6e 2d 73 74 61 72 74 65 efinition-starte
2280: 72 20 28 66 6f 6e 74 2d 6c 6f 63 6b 2d 6b 65 79 r (font-lock-key
2290: 77 6f 72 64 2d 66 61 63 65 20 2e 20 31 29 0a 20 word-face . 1).
22a0: 20 20 20 20 20 22 5b 20 5c 74 5c 6e 5d 22 20 74 "[ \t\n]" t
22b0: 20 6e 61 6d 65 20 28 66 6f 6e 74 2d 6c 6f 63 6b name (font-lock
22c0: 2d 66 75 6e 63 74 69 6f 6e 2d 6e 61 6d 65 2d 66 -function-name-f
22d0: 61 63 65 20 2e 20 33 29 29 0a 20 20 20 20 20 28 ace . 3)). (
22e0: 22 5b 61 2d 7a 30 2d 39 5d 2b 28 22 20 69 6d 6d "[a-z0-9]+(" imm
22f0: 65 64 69 61 74 65 20 28 66 6f 6e 74 2d 6c 6f 63 ediate (font-loc
2300: 6b 2d 63 6f 6d 6d 65 6e 74 2d 66 61 63 65 20 2e k-comment-face .
2310: 20 31 29 0a 20 20 20 20 20 20 22 29 22 20 6e 69 1). ")" ni
2320: 6c 20 63 6f 6d 6d 65 6e 74 20 28 66 6f 6e 74 2d l comment (font-
2330: 6c 6f 63 6b 2d 63 6f 6d 6d 65 6e 74 2d 66 61 63 lock-comment-fac
2340: 65 20 2e 20 31 29 29 0a 20 20 20 20 29 0a 66 6f e . 1)). ).fo
2350: 72 74 68 2d 6c 6f 63 61 6c 2d 69 6e 64 65 6e 74 rth-local-indent
2360: 2d 77 6f 72 64 73 3a 0a 20 20 20 20 28 0a 20 20 -words:. (.
2370: 20 20 20 28 28 22 6e 65 74 32 6f 3a 22 20 22 2b (("net2o:" "+
2380: 6e 65 74 32 6f 3a 22 29 20 28 30 20 2e 20 32 29 net2o:") (0 . 2)
2390: 20 28 30 20 2e 20 32 29 20 6e 6f 6e 2d 69 6d 6d (0 . 2) non-imm
23a0: 65 64 69 61 74 65 29 0a 20 20 20 20 29 0a 45 6e ediate). ).En
23b0: 64 3a 0a 5b 54 48 45 4e 5d 0a d:.[THEN].