Skip to content
This repository has been archived by the owner on Jul 23, 2023. It is now read-only.

Commit

Permalink
improve listpaysext.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Aug 12, 2020
1 parent d9ff7de commit dde1cb7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const DEFAULTPORT = "9737"
func main() {
p := plugin.Plugin{
Name: "sparko",
Version: "v2.2",
Version: "v2.3",
Options: []plugin.Option{
{"sparko-host", "string", "127.0.0.1", "http(s) server listen address"},
{"sparko-port", "string", DEFAULTPORT, "http(s) server port"},
Expand Down
32 changes: 17 additions & 15 deletions spark-methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,29 @@ var listpaysExt = plugin.RPCMethod{
return []bool{}, 0, nil
}

// more than 50, we filter
if len(pays) > 50 {
pays = pays[:50]
// more than 30, we filter
if len(pays) > 30 {
pays = pays[len(pays)-30:]
}

retval := make([]interface{}, len(pays))
// these are not currently available, but be prepared for when they are
if pays[0].Get("payment_hash").Exists() && pays[0].Get("created_at").Exists() {
return res.Value(), 0, nil
for i, pay := range pays {
retval[i] = pay.Value()
}
} else {
filled := make(chan interface{}, len(pays))
for _, pay := range pays {
go fillPay(p, pay, filled)
}
i := 0
for fpay := range filled {
retval[i] = fpay
i++
}
}

retval := make([]interface{}, len(pays))
filled := make(chan interface{}, len(pays))
for _, pay := range pays {
go fillPay(p, pay, filled)
}
i := 0
for fpay := range filled {
retval[i] = fpay
i++
}
return map[string]interface{}{"pays": retval}, 0, nil
},
}
Expand All @@ -112,7 +115,6 @@ func fillPay(p *plugin.Plugin, pay gjson.Result, filled chan<- interface{}) {
hash := sha256.Sum256(preimage)
hexhash := hex.EncodeToString(hash[:])
payv["payment_hash"] = hexhash

res, _ := p.Client.CallNamed("listsendpays", "payment_hash", hexhash)
payv["created_at"] = res.Get("payments.0.created_at").Int()

Expand Down

0 comments on commit dde1cb7

Please sign in to comment.