-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathhodlcontracts.py
1451 lines (1433 loc) · 83.3 KB
/
hodlcontracts.py
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import lightning_pb2 as ln
import lightning_pb2_grpc as lnrpc
import invoices_pb2 as invoicesrpc
import invoices_pb2_grpc as invoicesstub
import router_pb2 as routerrpc
import router_pb2_grpc as routerstub
import grpc
import os
import codecs
import requests
import json
import time
import sqlite3
import math
from random import *
from hashlib import sha256
from stem.control import Controller
from flask import Flask, redirect, url_for, request, make_response
os.environ[ "GRPC_SSL_CIPHER_SUITES" ] = 'HIGH+ECDSA'
cert = open( os.path.expanduser( '~/.lnd/tls.cert' ), 'rb' ).read()
with open( os.path.expanduser( '~/.lnd/data/chain/bitcoin/testnet/admin.macaroon'), 'rb' ) as f:
macaroon_bytes = f.read()
macaroon = codecs.encode( macaroon_bytes, 'hex' )
def metadata_callback( context, callback ):
callback( [ ( 'macaroon', macaroon ) ], None)
cert_creds = grpc.ssl_channel_credentials( cert )
auth_creds = grpc.metadata_call_credentials( metadata_callback )
combined_creds = grpc.composite_channel_credentials( cert_creds, auth_creds )
channel = grpc.secure_channel( 'localhost:10009', combined_creds )
stub = lnrpc.LightningStub( channel )
stub.GetInfo( ln.GetInfoRequest() )
def getInvoice( expiry, hash, amount ):
stub2 = invoicesstub.InvoicesStub( channel )
request = invoicesrpc.AddHoldInvoiceRequest(
hash=hash.decode( "hex" ),
value=amount,
expiry=expiry,
)
return stub2.AddHoldInvoice( request ).payment_request
def settleInvoice( preimage ):
addLog( "settle invoice is running with this preimage: " + preimage )
stub2 = invoicesstub.InvoicesStub( channel )
request = invoicesrpc.SettleInvoiceMsg(
preimage=preimage.decode( "hex" )
)
return stub2.SettleInvoice( request )
def cancelInvoice( pmthash ):
stub2 = invoicesstub.InvoicesStub( channel )
request = invoicesrpc.CancelInvoiceMsg(
payment_hash=pmthash.decode( "hex" )
)
return stub2.CancelInvoice( request )
def getStatus( id, party ):
contract_id = id
con = sqlite3.connect( "contracts.db" )
cur = con.cursor()
cur.execute( "SELECT contract from contracts WHERE contract_id = '" + contract_id + "'" )
contracts = cur.fetchone()
con.close()
datum = json.loads( contracts[ 0 ] )
if int( party ) == 1 and str( datum[ "first party original invoice" ] ) == "":
status = "No interaction yet"
if int( party ) == 1 and str( datum[ "first party original invoice" ] ) != "":
pmthash = str( datum[ "first party pmthash" ] )
request = ln.PaymentHash(
r_hash_str=pmthash
)
response = stub.LookupInvoice( request )
pmtstatus = response.state
if pmtstatus == 3:
status = "Contract funded, awaiting settlement"
elif pmtstatus == 2:
status = "Canceled"
elif pmtstatus == 1:
status = "Settled"
else:
status = "Waiting on other party"
if int( party ) == 2 and str( datum[ "second party original invoice" ] ) == "":
if str( datum[ "first party original invoice" ] ) == "":
status = "Waiting for other party"
else:
status = "No interaction yet"
if int( party ) == 2 and str( datum[ "second party original invoice" ] ) != "":
if str( datum[ "first party original invoice" ] ) == "":
status = "Waiting for other party"
else:
status = "No interaction yet"
pmthash = str( datum[ "second party pmthash" ] )
request = ln.PaymentHash(
r_hash_str=pmthash
)
response = stub.LookupInvoice( request )
pmtstatus = response.state
if pmtstatus == 3:
status = "Contract funded, awaiting settlement"
elif pmtstatus == 2:
status = "Canceled"
elif pmtstatus == 1:
status = "Settled"
else:
status = "Waiting on other party"
returnable = status
return returnable
"""
def payFirstParty( pmthash ):
returnable = "payment failed"
con = sqlite3.connect( "contracts.db" )
cur = con.cursor()
cur.execute( "SELECT first_party_original from contracts WHERE first_party_pmthash = '" + pmthash + "'" )
contract = cur.fetchone()
con.close()
original_invoice = ''.join( contract )
stub3 = routerstub.RouterStub( channel )
trypay = routerrpc.SendPaymentRequest(
payment_request=original_invoice,
timeout_seconds=15,
fee_limit_sat=10
)
fullresponse = []
for response in stub3.SendPayment( trypay ):
fullresponse.append( response )
if len( fullresponse ) > 2:
pmtstatus = fullresponse[ 2 ].state
if pmtstatus == 1:
pmtpmgbytes = str( fullresponse[ 2 ].preimage )
pmtpmghex = "".join("{:02x}".format(ord(c)) for c in pmtpmgbytes)
returnable = repr( settleInvoice( pmtpmghex ) )
def paySecondParty( pmthash ):
returnable = "payment failed"
con = sqlite3.connect( "contracts.db" )
cur = con.cursor()
cur.execute( "SELECT second_party_original from contracts WHERE first_party_pmthash = '" + pmthash + "'" )
contract = cur.fetchone()
con.close()
original_invoice = ''.join( contract )
stub3 = routerstub.RouterStub( channel )
trypay = routerrpc.SendPaymentRequest(
payment_request=original_invoice,
timeout_seconds=15,
fee_limit_sat=10
)
fullresponse = []
for response in stub3.SendPayment( trypay ):
fullresponse.append( response )
if len( fullresponse ) > 2:
pmtstatus = fullresponse[ 2 ].state
if pmtstatus == 1:
pmtpmgbytes = str( fullresponse[ 2 ].preimage )
pmtpmghex = "".join("{:02x}".format(ord(c)) for c in pmtpmgbytes)
returnable = repr( settleInvoice( pmtpmghex ) )
"""
def makeHash():
rand1 = int( math.floor( random() * 100000000000 ) )
rand2 = int( math.floor( random() * 100000000000 ) )
rand3 = int( math.floor( random() * 100000000000 ) )
rand4 = int( math.floor( random() * 100000000000 ) )
rand5 = int( math.floor( random() * 100000000000 ) )
rand6 = int( math.floor( random() * 100000000000 ) )
rand7 = int( math.floor( random() * 100000000000 ) )
rand = str( rand1 ) + str( rand2 ) + str( rand3 ) + str( rand4 ) + str( rand5 ) + str( rand6 ) + str( rand7 )
return sha256( rand.encode( 'utf-8' ) ).hexdigest()
def addLog( texttoadd ):
with open( 'debug.log', 'a' ) as f:
f.write( texttoadd + "\n" )
app = Flask(__name__)
@app.route( '/checkstatus/', methods=[ 'POST', 'GET' ] )
def checkStatus():
from flask import request
id = request.args.get( "id" )
party = request.args.get( "party" )
response = make_response(getStatus( id, party ), 200)
response.mimetype = "text/plain"
return response
@app.route( '/cancel/', methods=[ 'POST', 'GET' ] )
def canceler():
from flask import request
contract_id = request.args.get( "id" )
party = request.args.get( "party" )
con = sqlite3.connect( "contracts.db" )
cur = con.cursor()
cur.execute( "SELECT contract from contracts WHERE contract_id = '" + contract_id + "'" )
contracts = cur.fetchone()
con.close()
datum = json.loads( contracts[ 0 ] )
if int( party ) == 1:
pmthash = str( datum[ "first party pmthash" ] )
else:
pmthash = str( datum[ "second party pmthash" ] )
returnable = repr( cancelInvoice( pmthash ) )
return returnable
@app.route( '/settle/', methods=[ 'POST', 'GET' ] )
def settler():
from flask import request
contract_id = request.args.get( "id" )
trueorfalse = request.args.get( "true" )
con = sqlite3.connect( "contracts.db" )
cur = con.cursor()
cur.execute( "SELECT contract from contracts WHERE contract_id = '" + contract_id + "'" )
contracts = cur.fetchone()
con.close()
datum = json.loads( contracts[ 0 ] )
if int( trueorfalse ) == 1:
pmthash = str( datum[ "first party pmthash" ] )
request = ln.PaymentHash(
r_hash_str=pmthash
)
response = stub.LookupInvoice( request )
status = response.state
if status == 3:
addLog( "status: " + str( status ) )
original_invoice = str( datum[ "first party original invoice" ] )
addLog( "original invoice: " + str( datum[ "first party original invoice" ] ) )
stub3 = routerstub.RouterStub( channel )
trypay = routerrpc.SendPaymentRequest(
payment_request=original_invoice,
timeout_seconds=900,
fee_limit_sat=10
)
fullresponse = []
for response in stub3.SendPayment( trypay ):
fullresponse.append( response )
addLog( "full response: \n" + repr( fullresponse ) )
if len( fullresponse ) > 2:
pmtstatus = fullresponse[ 2 ].state
addLog( "payment status: " + str( pmtstatus ) )
if pmtstatus == 1:
pmtpmgbytes = str( fullresponse[ 2 ].preimage )
pmtpmghex = "".join("{:02x}".format(ord(c)) for c in pmtpmgbytes)
addLog( "payment preimage hex: " + pmtpmghex )
settleInvoice( pmtpmghex )
return pmtpmghex
else:
pmthash = str( datum[ "second party pmthash" ] )
request = ln.PaymentHash(
r_hash_str=pmthash
)
response = stub.LookupInvoice( request )
status = response.state
if status == 3:
original_invoice = str( datum[ "second party original invoice" ] )
stub3 = routerstub.RouterStub( channel )
trypay = routerrpc.SendPaymentRequest(
payment_request=original_invoice,
timeout_seconds=900,
fee_limit_sat=10
)
fullresponse = []
for response in stub3.SendPayment( trypay ):
fullresponse.append( response )
if len( fullresponse ) > 2:
pmtstatus = fullresponse[ 2 ].state
if pmtstatus == 1:
pmtpmgbytes = str( fullresponse[ 2 ].preimage )
pmtpmghex = "".join("{:02x}".format(ord(c)) for c in pmtpmgbytes)
settleInvoice( pmtpmghex )
return pmtpmghex
return ""
@app.route( '/contract/', methods=[ 'POST', 'GET' ] )
def contractpage():
returnable = ""
if request.form.get( "contract name" ) is not None and request.args.get( "processing" ) is not None:
if request.args.get( "id" ) is not None:
contract_id = request.args.get( "id" )
contract_name = request.form.get( "contract name" )
description = request.form.get( "description" )
first_party_role = request.form.get( "first partys role" )
first_party_amount = request.form.get( "first partys amount" )
second_party_role = request.form.get( "second partys role" )
second_party_amount = request.form.get( "second partys amount" )
settlement_date = request.form.get( "settlement date" )
automatic = 0
btc_price = ""
usdt_amount = ""
usdt_address = ""
if request.form.get( "btc price checkbox" ) is not None or request.form.get( "usdt checkbox" ) is not None:
automatic = 1
if request.form.get( "btc price" ) is not None:
btc_price = request.form.get( "btcvprice" )
if request.form.get( "usdt amount" ) is not None:
usdt_amount = request.form.get( "usdt amount" )
if request.form.get( "usdt address" ) is not None:
usdt_address = request.form.get( "usdt address" )
oracle_fee = request.form.get( "oracle fee" )
contract_params = {
"contract id": contract_id,
"contract name": contract_name,
"description": description,
"first party role": first_party_role,
"first party amount": first_party_amount,
"first party original invoice": "",
"first party hodl invoice": "",
"first party pmthash": "",
"private": 1,
"second party role": second_party_role,
"second party amount": second_party_amount,
"second party original invoice": "",
"second party hodl invoice": "",
"second party pmthash": "",
"settlement date": settlement_date,
"automatic": automatic,
"btc_price": btc_price,
"usdt_amount": usdt_amount,
"usdt_address": usdt_address,
"oracle_fee": oracle_fee
}
contract = json.dumps( contract_params )
con = sqlite3.connect( "contracts.db" )
cur = con.cursor()
cur.execute( """CREATE TABLE IF NOT EXISTS contracts (
contract text,
contract_id text,
contract_name text,
description text,
first_party_role text,
first_party_amount integer,
first_party_original text,
first_party_hodl text,
first_party_pmthash text,
second_party_role text,
second_party_amount text,
second_party_original text,
second_party_hodl text,
second_party_pmthash text,
settlement_date integer,
automatic integer,
btc_price integer,
usdt_amount integer,
usdt_address text,
private integer,
oracle_fee integer
)""" )
con.commit()
cur.execute( "INSERT INTO contracts VALUES ( :contract, :contract_id, :contract_name, :description, :first_party_role, :first_party_amount, :first_party_original, :first_party_hodl, :first_party_pmthash, :second_party_role, :second_party_amount, :second_party_original, :second_party_hodl, :second_party_pmthash, :settlement_date, :automatic, :btc_price, :usdt_amount, :usdt_address, :private, :oracle_fee )",
{ "contract": contract, "contract_id": contract_id, "contract_name": contract_name, "description": description, "first_party_role": first_party_role, "first_party_amount": first_party_amount, "first_party_original": "", "first_party_hodl": "", "first_party_pmthash": "", "second_party_role": second_party_role, "second_party_amount": second_party_amount, "second_party_original": "", "second_party_hodl": "", "second_party_pmthash": "", "settlement_date": settlement_date, "automatic": automatic, "btc_price": btc_price, "usdt_amount": usdt_amount, "usdt_address": usdt_address, "private": 0, "oracle_fee": oracle_fee } )
con.commit()
cur.execute( "SELECT * from contracts WHERE contract_id = '" + contract_id + "'" )
contracts = cur.fetchone()
con.close()
fullcontract = json.dumps( contracts )
returnable = """
<!DOCTYPE html>
<html style="min-height: 100%;">
<head>
<style>
* {{
box-sizing: border-box;
}}
</style>
</head>
<body style="height: 100%; margin: 0px; font-family: Helvetica, sans-serif;">
<div id="header" style="height: 50px; background-color: red;">
<h1 style="padding: 7px; color: white; margin: 0;">
Hodl contracts
</h1>
</div>
<div style="display: flex;">
<div id="leftside" style="min-height: calc( 100vh - 50px ); background-color: orange; width: 25%;">
</div>
<div id="middle" style="width: 50%; padding: 0 0.5rem;">
<div>
<h2>
Contract {contract_id_short}
</h2>
<p>
Your submission is being processed. If you are not redirected shortly, <a href="/contract/?id={contract_id}">click here</a>
</p>
</div>
</div>
<div id="rightside" style="background-color: blue; width: 25%;">
<div style="margin: 10px; color: white;">
</div>
</div>
</div>
<script>
setTimeout( function() {{ window.location.href = "/contract/?id={contract_id}" }}, 2500 );
</script>
</body>
</html>
""".format( contract_id_short = contract_id[ 0:10 ] + "...", contract_id = contract_id, fullcontract = fullcontract )
else:
if request.args.get( "id" ) is not None:
contract_id = request.args.get( "id" )
con = sqlite3.connect( "contracts.db" )
cur = con.cursor()
cur.execute( "SELECT contract FROM contracts WHERE contract_id = '" + contract_id + "'" )
contracts = cur.fetchone()
cur.execute( "SELECT contract FROM contracts" )
allcontracts = cur.fetchall()
set = '['
for ct in allcontracts:
set += json.dumps( json.loads( ct[ 0 ] ) ) + ","
set = set[0:-1]
set += ']'
allcontractsstring = set
con.close()
datum = json.loads( contracts[ 0 ] )
first_party_amount = str( datum[ "first party amount" ] )
second_party_amount = str( datum[ "second party amount" ] )
contract = json.dumps( datum )
returnable = """
<!DOCTYPE html>
<html style="min-height: 100%;">
<head>
<style>
* {{
box-sizing: border-box;
}}
</style>
</head>
<body style="height: 100%; margin: 0px; font-family: Helvetica, sans-serif;">
<div id="header" style="height: 50px; background-color: red;">
<h1 style="padding: 7px; color: white; margin: 0;">
Hodl contracts
</h1>
</div>
<div style="display: flex;">
<div id="leftside" style="min-height: calc( 100vh - 50px ); background-color: orange; width: 25%;">
<div style="margin: 10px;">
<h2>
All contracts
</h2>
<p id="all contracts">
</p>
</div>
</div>
<div id="middle" style="width: 50%; padding: 0 0.5rem;">
<div>
<h2>
Contract {contract_id_short}
</h2>
<div align="center">
<div id="1st party" style="display: inline-block; margin-left: 20px; margin-right: 20px;">
<p style="font-weight: bold; margin-bottom: 20px;">First party</p>
<p><span style="text-decoration: underline;">Status</span>: <span id="1status"></span></p>
<a id="1st party settlement" target="_blank">
<button type="button" id="first party settle button" style="color: white; border: 2px solid black; border-radius: 5px; height: 40px; font-size: 18px; cursor: not-allowed; margin-bottom: 20px; background-color: green; opacity: 0.3">
Settle
</button>
</a>
<br>
<a id="1st party cancelation" target="_blank">
<button type="button" id="first party cancel button" style="color: white; border: 2px solid black; border-radius: 5px; height: 40px; font-size: 18px; cursor: not-allowed; margin-bottom: 20px; background-color: red; opacity: 0.3">
Cancel
</button>
</a>
</div>
<div id="2nd party" style="display: inline-block; margin-left: 20px; margin-right: 20px;">
<p style="font-weight: bold; margin-bottom: 20px;">Second party</p>
<p><span style="text-decoration: underline;">Status</span>: <span id="2status"></span></p>
<a id="2nd party settlement" target="_blank">
<button type="button" id="second party settle button" style="color: white; border: 2px solid black; border-radius: 5px; height: 40px; font-size: 18px; cursor: not-allowed; margin-bottom: 20px; background-color: green; opacity: 0.3">
Settle
</button>
</a>
<br>
<a id="2nd party cancelation" target="_blank">
<button type="button" id="second party cancel button" style="color: white; border: 2px solid black; border-radius: 5px; height: 40px; font-size: 18px; cursor: not-allowed; margin-bottom: 20px; background-color: red; opacity: 0.3">
Cancel
</button>
</a>
</div>
</div>
<p id="description"></p>
<p>
Please send each counterparty a link to their page
</p>
<p align="center">
<a id="1st party link" target="_blank"><button type="button" style="border: 2px solid black; border-radius: 5px; height: 40px; font-size: 18px; cursor: pointer;">1st party's page</button></a>
<a id="2nd party link" target="_blank"><button type="button" style="border: 2px solid black; border-radius: 5px; height: 40px; font-size: 18px; cursor: pointer;">2nd party's page</button></a>
</p>
</div>
</div>
<div id="rightside" style="background-color: blue; width: 25%;">
<div style="margin: 10px; color: white;">
<h2>
New contract
</h2>
<div id="new contract" class="sidebarbtn" style="border: 2px solid white; border-radius: 5px; font-size: 18px; margin-bottom: 20px; cursor: pointer; text-align: center; padding: 0.5rem 0;">
Create new contract
</div>
</div>
</div>
</div>
<script>
document.getElementById( "new contract" ).addEventListener( "click", function() {{
window.location.href = "/admin/";
}});
</script>
<script>
function makeCBox( name, date, id ) {{
var div = '<a href="/contract/?id=' + id + '" style="text-decoration: none;"><div class="cbox" style="padding: 10px; background-color: white; border-radius: 10px; box-shadow: black 2px 2px 5px; margin-bottom: 10px; color: black;"><div class="clight" align="right" style="color: #4fd83a;">◉</div><div class="cname">' + name + '</div><div class="sdate" style="font-size: 14px; font-style: italic; margin-top: 5px;" align="right">' + date + '</div></div></a>';
return div;
}}
var allcontracts = {allcontracts};
allcontracts.reverse();
allcontracts.forEach( function( item ) {{
document.getElementById( "all contracts" ).innerHTML += makeCBox( item[ "contract name" ], item[ "settlement date" ], item[ "contract id" ] );
}});
</script>
<script>
function checkStatus( party ) {{
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {{
if ( this.readyState == 4 && this.status == 200 ) {{
document.getElementById( party + "status" ).innerText = xhttp.responseText;
if ( party == 1 ) {{
if ( xhttp.responseText == "Waiting on other party" ) {{
document.getElementById( "1st party settlement" ).removeAttribute( "href" );
document.getElementById( "first party settle button" ).style.cursor = "not-allowed";
document.getElementById( "first party settle button" ).style.opacity = "0.3";
document.getElementById( "1st party cancelation" ).href = "/cancel/?id=" + json[ "contract id" ] + "&party=1";
document.getElementById( "first party cancel button" ).style.cursor = "pointer";
document.getElementById( "first party cancel button" ).style.opacity = 1;
}} else if ( xhttp.responseText == "Contract funded, awaiting settlement" ) {{
document.getElementById( "1st party settlement" ).href = "/settle/?id=" + json[ "contract id" ] + "&true=1";
document.getElementById( "first party settle button" ).style.cursor = "pointer";
document.getElementById( "first party settle button" ).style.opacity = 1;
document.getElementById( "1st party cancelation" ).href = "/cancel/?id=" + json[ "contract id" ] + "&party=1";
document.getElementById( "first party cancel button" ).style.cursor = "pointer";
document.getElementById( "first party cancel button" ).style.opacity = 1;
}} else {{
document.getElementById( "1st party settlement" ).removeAttribute( "href" );
document.getElementById( "first party settle button" ).style.cursor = "not-allowed";
document.getElementById( "first party settle button" ).style.opacity = "0.3";
document.getElementById( "1st party cancelation" ).removeAttribute( "href" );
document.getElementById( "first party cancel button" ).style.cursor = "not-allowed";
document.getElementById( "first party cancel button" ).style.opacity = "0.3";
}}
}}
if ( party == 2 ) {{
if ( xhttp.responseText == "Waiting on other party" ) {{
document.getElementById( "2nd party settlement" ).removeAttribute( "href" );
document.getElementById( "second party settle button" ).style.cursor = "not-allowed";
document.getElementById( "second party settle button" ).style.opacity = "0.3";
document.getElementById( "2nd party cancelation" ).href = "/cancel/?id=" + json[ "contract id" ] + "&party=2";
document.getElementById( "second party cancel button" ).style.cursor = "pointer";
document.getElementById( "second party cancel button" ).style.opacity = 1;
}} else if ( xhttp.responseText == "Contract funded, awaiting settlement" ) {{
document.getElementById( "2nd party settlement" ).href = "/settle/?id=" + json[ "contract id" ] + "&true=0";
document.getElementById( "second party settle button" ).style.cursor = "pointer";
document.getElementById( "second party settle button" ).style.opacity = 1;
document.getElementById( "2nd party cancelation" ).href = "/cancel/?id=" + json[ "contract id" ] + "&party=2";
document.getElementById( "second party cancel button" ).style.cursor = "pointer";
document.getElementById( "second party cancel button" ).style.opacity = 1;
}} else {{
document.getElementById( "2nd party settlement" ).removeAttribute( "href" );
document.getElementById( "second party settle button" ).style.cursor = "not-allowed";
document.getElementById( "second party settle button" ).style.opacity = "0.3";
document.getElementById( "2nd party cancelation" ).removeAttribute( "href" );
document.getElementById( "second party cancel button" ).style.cursor = "not-allowed";
document.getElementById( "second party cancel button" ).style.opacity = "0.3";
}}
}}
console.log( "first party amount: {fpamt}" );
console.log( "second party amount: {spamt}" );
}}
}}
xhttp.open( "GET", "/checkstatus/?id={contract_id}&party=" + party, true );
xhttp.send();
}}
function loopStatus( party ) {{
checkStatus( party );
if ( document.getElementById( party + "status" ).innerText != "Canceled" && document.getElementById( party + "status" ).innerText != "Settled" ) {{
setTimeout( function() {{ loopStatus( party ); }}, 5000 );
}}
}}
loopStatus( 1 );
loopStatus( 2 );
</script>
<script>
json = {contract};
document.getElementById( "description" ).innerText = json[ "description" ];
document.getElementById( "1st party link" ).href = "/?id=" + json[ "contract id" ] + "&party=1";
document.getElementById( "2nd party link" ).href = "/?id=" + json[ "contract id" ] + "&party=2";
</script>
</body>
</html>
""".format( contract_id_short = contract_id[ 0:10 ] + "...", contract_id = contract_id, contract = contract, allcontracts = allcontractsstring, fpamt = first_party_amount, spamt = second_party_amount )
return returnable
@app.route( '/admin/', methods=[ 'POST', 'GET' ] )
def adminpage():
con = sqlite3.connect( "contracts.db" )
cur = con.cursor()
cur.execute( """CREATE TABLE IF NOT EXISTS contracts (
contract text,
contract_id text,
contract_name text,
description text,
first_party_role text,
first_party_amount integer,
first_party_original text,
first_party_hodl text,
first_party_pmthash text,
second_party_role text,
second_party_amount text,
second_party_original text,
second_party_hodl text,
second_party_pmthash text,
settlement_date integer,
automatic integer,
btc_price integer,
usdt_amount integer,
usdt_address text,
private integer,
oracle_fee integer
)""" )
con.commit()
con.close()
contract_id = makeHash()
con = sqlite3.connect( "contracts.db" )
cur = con.cursor()
cur.execute( "SELECT contract FROM contracts" )
allcontracts = cur.fetchall()
set = '['
for ct in allcontracts:
set += json.dumps( json.loads( ct[ 0 ] ) ) + ","
set = set[0:-1]
set += ']'
allcontractsstring = set
con.close()
returnable = """
<!DOCTYPE html>
<html style="min-height: 100%">
<head>
<style>
* {{
box-sizing: border-box;
}}
</style>
</head>
<body style="height: 100%; margin: 0px; font-family: Helvetica, sans-serif;">
<div id="header" style="height: 50px; background-color: red;">
<h1 style="padding: 7px; color: white; margin: 0;">
Hodl Contracts
</h1>
</div>
<div style="display: flex;">
<div id="leftside" style="min-height: calc( 100vh - 50px ); background-color: orange; width: 25%;">
<div style="margin: 10px;">
<h2>
All contracts
</h2>
<p id="all contracts"></p>
</div>
</div>
<div id="middle" style="width: 50%; padding: 0 0.5rem;">
<div>
<h2>
New contract
</h2>
<form method="post" action="/contract/?id={contract_id}&processing=true">
<p style="font-weight: bold;">
Contract name
</p>
<input type="text" style="width: 100%; border: 2px solid black; border-radius: 5px; height: 40px; font-size: 18px;" id="contract name" name="contract name">
<p style="font-weight: bold;">
Contract description
</p>
<textarea style="width: 100%; border: 2px solid black; border-radius: 5px; height: 140px; font-family: Helvetica, sans-serif; font-size: 18px;" type="text" id="description" name="description"></textarea>
<p style="font-weight: bold;">
Settlement date
</p>
<input type="date" placeholder="12/25/2020" style="width: 100%; border: 2px solid black; border-radius: 5px; height: 40px; font-size: 18px;" type="text" id="settlement date" name="settlement date">
<p style="font-weight: bold;">
First party's role
</p>
<input type="text" style="width: 100%; border: 2px solid black; border-radius: 5px; height: 40px; font-size: 18px;" id="first partys role" name="first partys role" placeholder="Buyer">
<p style="font-weight: bold;">
Second party's role
</p>
<input type="text" style="width: 100%; border: 2px solid black; border-radius: 5px; height: 40px; font-size: 18px;" id="second partys role" name="second partys role" placeholder="Seller">
<p style="font-weight: bold;">
How much will the first party send to the second party via bitcoin?
</p>
<span style="display: inline-block; width: 10px;">$</span> <input type="number" style="width: calc( 100% - 15px ); border: 2px solid black; border-radius: 5px; height: 40px; font-size: 18px;" id="first partys amount" name="first partys amount" placeholder="100.00">
<p style="font-weight: bold;">
How much will the second party send to the first party via bitcoin?
</p>
<span style="display: inline-block; width: 10px;">$</span> <input type="number" style="width: calc( 100% - 15px ); border: 2px solid black; border-radius: 5px; height: 40px; font-size: 18px;" id="second partys amount" name="second partys amount" placeholder="0.00">
<p style="font-weight: bold;">
Oracle fee
</p>
<span style="display: inline-block; width: 10px;">$</span> <input type="number" style="width: calc( 100% - 15px ); border: 2px solid black; border-radius: 5px; height: 40px; font-size: 18px;" id="oracle fee" name="oracle fee" placeholder="1.00" step="0.01">
<h3 style="text-decoration: underline; cursor: pointer;" onclick="if ( this.nextElementSibling.style.display != 'none' ) {{this.nextElementSibling.style.display = 'none'; }} else {{this.nextElementSibling.style.display = 'block';}}">
Advanced (only for automated oracle contracts)
</h3>
<div id="advanced options" style="display: none;">
<div style="margin-bottom: 20px;">
<p>
Be aware that if you check either of these boxes your contract will execute automatically on the settlement date you specify above
</p>
<input type="checkbox" id="btc price checkbox" name="btc price checkbox">
<label for="btc price checkbox">
Price condition: if bitcoin's price is above <span>$</span> <input type="number" style="width: 120px; border: 2px solid black; border-radius: 5px; height: 40px; font-size: 18px;" id="btc price" name="btc price" placeholder="100000.00"> send the btc to the first party, otherwise it will be sent to the second party
</label>
</div>
<div>
<input type="checkbox" id="usdt checkbox" name="usdt checkbox">
<label for="usdt checkbox">
USDT condition: if omni explorer says that an output of <span>$</span> <input type="number" style="width: 120px; border: 2px solid black; border-radius: 5px; height: 40px; font-size: 18px;" id="usdt amount" name="usdt amount" placeholder="100.00"> or more USDT was in <input type="text" style="width: 120px; border: 2px solid black; border-radius: 5px; height: 40px; font-size: 18px;" id="usdt address" name="usdt address" placeholder="1abc234def567ghi"> address, it will be sent to the first party, otherwise it will be sent to the second party
</label>
</div>
</div>
<p>
<button type="submit" style="border: 2px solid black; border-radius: 5px; height: 40px; font-size: 18px; cursor: pointer;">Submit</button>
</p>
</form>
</div>
</div>
<div id="rightside" style="background-color: blue; width: 25%;">
<div style="margin: 10px; color: white;">
<h2>
Contract templates
</h2>
<div id="trading template" class="sidebarbtn" style="border: 2px solid white; border-radius: 5px; font-size: 18px; margin-bottom: 20px; cursor: pointer; text-align: center; padding: 0.5rem 0;">
Trading contract
</div>
<div id="loan template" class="sidebarbtn" style="border: 2px solid white; border-radius: 5px; font-size: 18px; margin-bottom: 20px; cursor: pointer; text-align: center; padding: 0.5rem 0;">
Loan contract
</div>
<div id="betting template" class="sidebarbtn" style="border: 2px solid white; border-radius: 5px; font-size: 18px; margin-bottom: 20px; cursor: pointer; text-align: center; padding: 0.5rem 0;">
Betting contract
</div>
</div>
</div>
</div>
<script>
function makeCBox( name, date, id ) {{
var div = '<a href="/contract/?id=' + id + '" style="text-decoration: none;"><div class="cbox" style="padding: 10px; background-color: white; border-radius: 10px; box-shadow: black 2px 2px 5px; margin-bottom: 10px; color: black;"><div class="clight" align="right" style="color: #4fd83a;">◉</div><div class="cname">' + name + '</div><div class="sdate" style="font-size: 14px; font-style: italic; margin-top: 5px;" align="right">' + date + '</div></div></a>';
return div;
}}
var allcontracts = {allcontracts};
allcontracts.reverse();
allcontracts.forEach( function( item ) {{
document.getElementById( "all contracts" ).innerHTML += makeCBox( item[ "contract name" ], item[ "settlement date" ], item[ "contract id" ] );
}});
</script>
<script>
function checkStatus( party ) {{
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {{
if ( this.readyState == 4 && this.status == 200 ) {{
document.getElementById( party + "status" ).innerText = xhttp.responseText;
}}
}}
xhttp.open( "GET", "/checkstatus/?id={contract_id}&party=" + party, true );
xhttp.send();
}}
function loopStatus( party ) {{
checkStatus( party );
if ( document.getElementById( party + "status" ).innerText != "Canceled" && document.getElementById( party + "status" ).innerText != "Settled" ) {{
setTimeout( function() {{ loopStatus( party ); }}, 5000 );
}}
}}
</script>
<script>
document.getElementById( "trading template" ).addEventListener( "click", function() {{
document.getElementById( "contract name" ).value = "Janice trades with Joe, $100 in bitcoin for $100 in usd";
document.getElementById( "description" ).value = "The 1st party submits an invoice for $100 and hands the 2nd party $100 usd. The 2nd party pays the invoice and the oracle settles that invoice. This completes the contract in the happy case. There are two unhappy cases. If the 2nd party doesn't send the bitcoins, the contract expires on the settlement date. No one loses any money but no one is happy. If the 1st party doesn't hand over the usd, the oracle cancels the 1st party's invoice. No one loses any money but no one is happy.";
var d = new Date();
document.getElementById( "settlement date" ).value = d.toISOString().substr( 0, 10 );
document.getElementById( "first partys role" ).value = "Bitcoin buyer";
document.getElementById( "second partys role" ).value = "Bitcoin seller";
document.getElementById( "first partys amount" ).value = "0.00";
document.getElementById( "second partys amount" ).value = "100.00";
document.getElementById( "oracle fee" ).value = "1.00";
}});
document.getElementById( "loan template" ).addEventListener( "click", function() {{
document.getElementById( "contract name" ).value = "Timothy lends $100 to Olivia";
document.getElementById( "description" ).value = "The 1st party submits an invoice for $200 and hands over $100 usd. The 2nd party pays the invoice to overcollateralize his position. By the settlement date he hands back the $100 usd plus interest. The oracle cancels the 1st party's invoice. This concludes the contract in the happy case. There are several unhappy cases. If the 1st party does not submit an invoice, no one loses any money but no one is happy. If the 1st party submits an invoice and the 2nd party pays it but the 1st party doesn't hand over the usd by the settlement date, the oracle cancels the invoice. No one loses any money but no one is happy. If the 1st party does everything right but the 2nd party doesn't hand over the usd plus interest, the oracle settles the invoice and the lender uses it to cover his losses. The borrower loses money and is unhappy but he also is to blame because he did not pay his principle plus interest. If the price of bitcoin dips and the collateral is nearly not worth $100 anymore, the oracle settles the invoice. The lender keeps a bit more than $100 in btc and the borrower keeps $100 in usd. Neither one is perfectly happy but it's fair enough that many will be fine with it.";
var d = new Date();
document.getElementById( "settlement date" ).value = d.toISOString().substr( 0, 10 );
document.getElementById( "first partys role" ).value = "Lender";
document.getElementById( "second partys role" ).value = "Borrower";
document.getElementById( "first partys amount" ).value = "0.00";
document.getElementById( "second partys amount" ).value = "200.00";
document.getElementById( "oracle fee" ).value = "1.00";
}});
document.getElementById( "betting template" ).addEventListener( "click", function() {{
document.getElementById( "contract name" ).value = "The Steeltops versus the Rockets";
document.getElementById( "description" ).value = "Both parties submit an invoice for $100 and pay each other, then wait. On the settlement date, the oracle settles the winner's invoice and cancels the loser's. The loser may be unhappy but he lost fair and square.";
var d = new Date();
document.getElementById( "settlement date" ).value = d.toISOString().substr( 0, 10 );
document.getElementById( "first partys role" ).value = "Gambler";
document.getElementById( "second partys role" ).value = "Gambler";
document.getElementById( "first partys amount" ).value = "100.00";
document.getElementById( "second partys amount" ).value = "100.00";
document.getElementById( "oracle fee" ).value = "1.00";
}});
</script>
</body>
</html>
""".format( contract_id_short = contract_id[ 0:10 ] + "...", contract_id=contract_id, allcontracts = allcontractsstring )
return returnable
@app.route( '/', methods=[ 'POST', 'GET' ] )
def extractor():
if request.args.get( "id" ) is not None:
contract_id = request.args.get( "id" )
con = sqlite3.connect( "contracts.db" )
cur = con.cursor()
cur.execute( "SELECT contract from contracts WHERE contract_id = '" + contract_id + "'" )
contracts = cur.fetchone()
con.close()
pricect = json.loads( contracts[ 0 ] )
pricefeed = requests.get('https://api.kraken.com/0/public/Ticker?pair=XBTUSD')
krakenprice = pricefeed.json().get( "result" ).get( "XXBTZUSD" ).get( "a" )[ 0 ]
sats_per_dollar = int( float( "%.8f" % float( 100000000 // int( float ( krakenprice ) ) ) ) )
server_fee = int( float( pricect[ "oracle_fee" ] ) ) * sats_per_dollar
if request.args.get( "party" ) == "1" and request.args.get( "id" ) is not None and request.args.get( "processing" ) is not None:
returnable = "You already submitted an invoice"
contract_id = request.args.get( "id" )
con = sqlite3.connect( "contracts.db" )
cur = con.cursor()
cur.execute( "SELECT contract from contracts WHERE contract_id = '" + contract_id + "'" )
contracts = cur.fetchone()
con.close()
datum = json.loads( contracts[ 0 ] )
if str( datum[ "first party hodl invoice" ] ) == "":
first_party_original_invoice = request.form.get( "invoice" )
query = ln.PayReqString(
pay_req=first_party_original_invoice
)
response = stub.DecodePayReq( query )
newexpiry = ( ( response.timestamp + response.expiry ) - int( time.time() ) ) - 5
first_party_pmthash = str( response.payment_hash )
amount = response.num_satoshis + server_fee
first_party_hodl_invoice = getInvoice( newexpiry, first_party_pmthash, amount )
contract_name = str( datum[ "contract name" ] )
description = str( datum[ "description" ] )
first_party_role = str( datum[ "first party role" ] )
first_party_amount = str( datum[ "first party amount" ] )
second_party_role = str( datum[ "second party role" ] )
second_party_amount = str( datum[ "second party amount" ] )
second_party_original_invoice = str( datum[ "second party original invoice" ] )
second_party_hodl_invoice = str( datum[ "second party hodl invoice" ] )
second_party_pmthash = str( datum[ "second party pmthash" ] )
settlement_date = str( datum[ "settlement date" ] )
automatic = str( datum[ "automatic" ] )
btc_price = str( datum[ "btc_price" ] )
usdt_amount = str( datum[ "usdt_amount" ] )
usdt_address = str( datum[ "usdt_address" ] )
oracle_fee = str( datum[ "oracle_fee" ] )
contract_params = {
"contract id": contract_id,
"contract name": contract_name,
"description": description,
"first party role": first_party_role,
"first party amount": first_party_amount,
"first party original invoice": first_party_original_invoice,
"first party hodl invoice": first_party_hodl_invoice,
"first party pmthash": first_party_pmthash,
"private": 1,
"second party role": second_party_role,
"second party amount": second_party_amount,
"second party original invoice": second_party_original_invoice,
"second party hodl invoice": second_party_hodl_invoice,
"second party pmthash": second_party_pmthash,
"settlement date": settlement_date,
"automatic": automatic,
"btc_price": btc_price,
"usdt_amount": usdt_amount,
"usdt_address": usdt_address,
"oracle_fee": oracle_fee
}
contract = json.dumps( contract_params )
con = sqlite3.connect( "contracts.db" )
cur = con.cursor()
cur.execute( "UPDATE contracts SET contract = :contract, contract_id = :contract_id, contract_name = :contract_name, description = :description, first_party_role = :first_party_role, first_party_amount = :first_party_amount, first_party_original = :first_party_original, first_party_hodl = :first_party_hodl, first_party_pmthash = :first_party_pmthash, second_party_role = :second_party_role, second_party_amount = :second_party_amount, second_party_original = :second_party_original, second_party_hodl = :second_party_hodl, second_party_pmthash = :second_party_pmthash, settlement_date = :settlement_date, automatic = :automatic, btc_price = :btc_price, usdt_amount = :usdt_amount, usdt_address = :usdt_address, private = :private, oracle_fee = :oracle_fee WHERE contract_id = :contract_id",
{ "contract": contract, "contract_id": contract_id, "contract_name": contract_name, "description": description, "first_party_role": first_party_role, "first_party_amount": first_party_amount, "first_party_original": "", "first_party_hodl": "", "first_party_pmthash": "", "second_party_role": second_party_role, "second_party_amount": second_party_amount, "second_party_original": "", "second_party_hodl": "", "second_party_pmthash": "", "settlement_date": settlement_date, "automatic": automatic, "btc_price": btc_price, "usdt_amount": usdt_amount, "usdt_address": usdt_address, "private": 0, "oracle_fee": oracle_fee } )
con.commit()
returnable = """
<!DOCTYPE html>
<html style="min-height: 100%">
<head>
<style>
* {{
box-sizing: border-box;
}}
</style>
</head>
<body style="height: 100%; margin: 0px; font-family: Helvetica, sans-serif;">
<div id="header" style="height: 50px; background-color: red;">
<h1 style="padding: 7px; color: white; margin: 0;">
Hodl contracts
</h1>
</div>
<div style="display: flex;">
<div id="leftside" style="min-height: calc( 100vh - 50px ); background-color: orange; width: 25%;">
</div>
<div id="middle" style="width: 50%; padding: 0 0.5rem;">
<div>
<h2>
Contract {contract_id_short}
</h2>
<p>
Your submission is being processed. If you are not redirected shortly, <a href="/?id={contract_id}&party={party}">click here</a>
</p>
</div>
</div>
<div id="rightside" style="background-color: blue; width: 25%;">
<div style="margin: 10px; color: white;"></div>
</div>
</div>
<script>
setTimeout( function() {{ window.location.href = "/?id={contract_id}&party={party}" }}, 2500 );
</script>
</body>
</html>
""".format( contract_id_short = contract_id[ 0:10 ] + "...", contract_id = contract_id, party = str( request.args.get( "party" ) ) )
return returnable
if request.args.get( "party" ) == "1" and request.args.get( "id" ) is not None and request.args.get( "processing" ) is None:
contract_id = request.args.get( "id" )
con = sqlite3.connect( "contracts.db" )
cur = con.cursor()
cur.execute( "SELECT contract from contracts WHERE contract_id = '" + contract_id + "'" )
contracts = cur.fetchone()
con.close()
datum = json.loads( contracts[ 0 ] )
contract = json.dumps( datum )
fpinvoice = str( datum[ "first party hodl invoice" ] )
spinvoice = str( datum[ "second party hodl invoice" ] )
p1amt = str( datum[ "first party amount" ] )
p2amt = str( datum[ "second party amount" ] )
returnable = """
<!DOCTYPE html>
<html style="min-height: 100%">
<head>
<style>
* {{
box-sizing: border-box;
}}
</style>
</head>
<body style="height: 100%; margin: 0px; font-family: Helvetica, sans-serif;">
<script src="{qrcodejsfile}"></script>
<div id="header" style="height: 50px; background-color: red;">
<h1 style="padding: 7px; color: white; margin: 0;">
Hodl contracts
</h1>
</div>
<div style="display: flex;">
<div id="leftside" style="min-height: calc( 100vh - 50px ); background-color: orange; width: 25%;">
</div>
<div id="middle" style="width: 50%; padding: 0 0.5rem;">
<div>
<h2>
Contract {contract_id_short}
</h2>
<p id="description"></p>
<form method="post" action="/?processing=true&id={contract_id}&party={party}" style="display: none;">
<p>
Enter an invoice <span id="invoice amount"></span>
</p>
<p>
<input type="text" style="width: 100%; border: 2px solid black; border-radius: 5px; height: 40px; font-size: 18px;" id="invoice" name="invoice" placeholder="lnbc1482n0jf9t0wasfjfas9f20fj0fa0...">
</p>
<p>
<button type="submit" style="border: 2px solid black; border-radius: 5px; height: 40px; font-size: 18px; cursor: pointer;">Submit</button>
</p>
</form>
<div id="invoice container" style="display: none;">
Deposit funds to this smart contract<br>
<a href="lightning:{spinvoice}">
<div id="invoice div" style="max-width: 300px; margin: auto;">
</div>
</a>
</div>
<p id="instructions" style="display: none;">
<span id="instructions if invoiced" style="display: none;">You have already submitted your invoice. </span><span id="instructions if awaiting counterparty invoice" style="display: none;">Please wait while your counterparty creates an invoice. Check back later. </span><span id="instructions if awaiting counterparty deposit" style="display: none;">Please wait while your counterparty pays your invoice. Check back later. </span><span id="instructions if awaiting settlement" style="display: none;">Please await your settlement date (visible in the contract details below) and contact your oracle for more info.</span>
</p>
<p id="payment received" style="display: none;">
You received a payment from your counterparty
</p>
<p id="payment sent" style="display: none;">
Your payment to your counterparty went through
</p>
<p id="payment not received" style="display: none;">
The oracle canceled a payment from your counterparty to you
</p>
<p id="payment not sent" style="display: none;">
The oracle canceled a payment from you to your counterparty
</p>