Skip to content
This repository was archived by the owner on Apr 11, 2022. It is now read-only.

Commit 6fb811b

Browse files
author
fiatjaf
committed
basic git-database functionality working.
1 parent ff83c57 commit 6fb811b

23 files changed

+914
-1197
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ browserify-cache.json
1212
runcall
1313
static/*bundle*
1414
.pyre
15+
gitdatabase

account_functions.go

Lines changed: 26 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,28 @@ package main
33
import (
44
"crypto/hmac"
55
"crypto/sha256"
6-
"database/sql"
76
"encoding/hex"
87
"encoding/json"
98
"errors"
109
"fmt"
1110
"net/http"
1211
"sort"
1312

14-
"github.com/fiatjaf/etleneum/types"
15-
"gopkg.in/antage/eventsource.v1"
13+
"github.com/fiatjaf/etleneum/data"
1614
)
1715

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-
2416
func getAccountSecret(account string) string {
2517
hash := sha256.Sum256([]byte(account + "-" + s.SecretKey))
2618
return hex.EncodeToString(hash[:])
2719
}
2820

29-
func hmacCall(call *types.Call) []byte {
21+
func hmacCall(call *data.Call) []byte {
3022
mac := hmac.New(sha256.New, []byte(getAccountSecret(call.Caller)))
3123
mac.Write([]byte(callHmacString(call)))
3224
return mac.Sum(nil)
3325
}
3426

35-
func callHmacString(call *types.Call) (res string) {
27+
func callHmacString(call *data.Call) (res string) {
3628
res = fmt.Sprintf("%s:%s:%d,", call.ContractId, call.Method, call.Msatoshi)
3729

3830
var payload map[string]interface{}
@@ -57,47 +49,29 @@ func callHmacString(call *types.Call) (res string) {
5749
return
5850
}
5951

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+
// }
10175

10276
func hmacAccount(accountId string) string {
10377
mac := hmac.New(sha256.New, []byte(s.SecretKey))

0 commit comments

Comments
 (0)