@@ -3,36 +3,28 @@ package main
3
3
import (
4
4
"crypto/hmac"
5
5
"crypto/sha256"
6
- "database/sql"
7
6
"encoding/hex"
8
7
"encoding/json"
9
8
"errors"
10
9
"fmt"
11
10
"net/http"
12
11
"sort"
13
12
14
- "github.com/fiatjaf/etleneum/types"
15
- "gopkg.in/antage/eventsource.v1"
13
+ "github.com/fiatjaf/etleneum/data"
16
14
)
17
15
18
- func loadAccount (accountId string ) (types.Account , error ) {
19
- var acct types.Account
20
- err := pg .Get (& acct , `SELECT ` + types .ACCOUNTFIELDS + ` FROM accounts WHERE id = $1` , accountId )
21
- return acct , err
22
- }
23
-
24
16
func getAccountSecret (account string ) string {
25
17
hash := sha256 .Sum256 ([]byte (account + "-" + s .SecretKey ))
26
18
return hex .EncodeToString (hash [:])
27
19
}
28
20
29
- func hmacCall (call * types .Call ) []byte {
21
+ func hmacCall (call * data .Call ) []byte {
30
22
mac := hmac .New (sha256 .New , []byte (getAccountSecret (call .Caller )))
31
23
mac .Write ([]byte (callHmacString (call )))
32
24
return mac .Sum (nil )
33
25
}
34
26
35
- func callHmacString (call * types .Call ) (res string ) {
27
+ func callHmacString (call * data .Call ) (res string ) {
36
28
res = fmt .Sprintf ("%s:%s:%d," , call .ContractId , call .Method , call .Msatoshi )
37
29
38
30
var payload map [string ]interface {}
@@ -57,47 +49,29 @@ func callHmacString(call *types.Call) (res string) {
57
49
return
58
50
}
59
51
60
- func notifyHistory (es eventsource.EventSource , accountId string ) {
61
- var history []types.AccountHistoryEntry
62
- err := pg .Select (& history ,
63
- `SELECT ` + types .ACCOUNTHISTORYFIELDS + `
64
- FROM account_history WHERE account_id = $1` ,
65
- accountId )
66
- if err != nil && err != sql .ErrNoRows {
67
- log .Error ().Err (err ).Str ("id" , accountId ).
68
- Msg ("failed to load account history from session" )
69
- return
70
- } else if err == sql .ErrNoRows {
71
- es .SendEventMessage ("[]" , "history" , "" )
72
- } else {
73
- jhistory , _ := json .Marshal (history )
74
- es .SendEventMessage (string (jhistory ), "history" , "" )
75
- }
76
- }
77
-
78
- func deleteFailedWithdrawals () error {
79
- var bolt11s []string
80
- err := pg .Select (& bolt11s , `SELECT bolt11 FROM withdrawals WHERE NOT fulfilled` )
81
- if err != nil {
82
- return err
83
- }
84
-
85
- for _ , bolt11 := range bolt11s {
86
- listpays , err := ln .Call ("listpays" , bolt11 )
87
- if err != nil {
88
- return err
89
- }
90
- if listpays .Get ("pays.#" ).Int () == 0 || listpays .Get ("pays.0.status" ).String () == "failed" {
91
- // delete failed withdraw attempt
92
- pg .Exec ("DELETE FROM withdrawals WHERE bolt11 = $1 AND NOT fulfilled" , bolt11 )
93
- } else if listpays .Get ("pays.0.status" ).String () == "complete" {
94
- // mark as not pending anymore
95
- pg .Exec ("UPDATE withdrawals SET fulfilled = true WHERE bolt11 = $1 AND NOT fulfilled" , bolt11 )
96
- }
97
- }
98
-
99
- return nil
100
- }
52
+ // func deleteFailedWithdrawals() error {
53
+ // var bolt11s []string
54
+ // err := pg.Select(&bolt11s, `SELECT bolt11 FROM withdrawals WHERE NOT fulfilled`)
55
+ // if err != nil {
56
+ // return err
57
+ // }
58
+ //
59
+ // for _, bolt11 := range bolt11s {
60
+ // listpays, err := ln.Call("listpays", bolt11)
61
+ // if err != nil {
62
+ // return err
63
+ // }
64
+ // if listpays.Get("pays.#").Int() == 0 || listpays.Get("pays.0.status").String() == "failed" {
65
+ // // delete failed withdraw attempt
66
+ // pg.Exec("DELETE FROM withdrawals WHERE bolt11 = $1 AND NOT fulfilled", bolt11)
67
+ // } else if listpays.Get("pays.0.status").String() == "complete" {
68
+ // // mark as not pending anymore
69
+ // pg.Exec("UPDATE withdrawals SET fulfilled = true WHERE bolt11 = $1 AND NOT fulfilled", bolt11)
70
+ // }
71
+ // }
72
+ //
73
+ // return nil
74
+ // }
101
75
102
76
func hmacAccount (accountId string ) string {
103
77
mac := hmac .New (sha256 .New , []byte (s .SecretKey ))
0 commit comments