Skip to content

Commit 63a7732

Browse files
committed
add support for arweave transactions
fix a bit of a mess remove unused code
1 parent f4cec79 commit 63a7732

File tree

10 files changed

+197
-105
lines changed

10 files changed

+197
-105
lines changed

commentapi/comment.go

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ type CreateArgs struct {
9090
IsProtected bool `json:"is_protected"`
9191
Amount *float64 `json:"amount"`
9292
DryRun bool `json:"dry_run"`
93+
PaymentTxId *string `json:"payment_tx_id"`
9394
}
9495

9596
// CreateResponse response for the comment.Create rpc call

go.mod

+19-19
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ require (
88
github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32
99
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d
1010
github.com/caarlos0/env v3.5.0+incompatible
11-
github.com/coreos/go-oidc/v3 v3.11.0
12-
github.com/fatih/color v1.17.0
11+
github.com/coreos/go-oidc/v3 v3.12.0
12+
github.com/fatih/color v1.18.0
1313
github.com/fatih/structs v1.1.0
1414
github.com/friendsofgo/errors v0.9.2
1515
github.com/go-co-op/gocron v1.37.0
16-
github.com/go-sql-driver/mysql v1.8.1
16+
github.com/go-sql-driver/mysql v1.9.0
1717
github.com/gorilla/mux v1.8.1
1818
github.com/gorilla/rpc v1.2.1
1919
github.com/gorilla/websocket v1.5.3
@@ -27,20 +27,20 @@ require (
2727
github.com/lbryio/ozzo-validation v3.0.3-0.20170512160344-202201e212ec+incompatible
2828
github.com/mitchellh/mapstructure v1.5.0
2929
github.com/pkg/profile v1.7.0
30-
github.com/prometheus/client_golang v1.20.4
30+
github.com/prometheus/client_golang v1.21.0
3131
github.com/rs/cors v1.11.1
32-
github.com/rubenv/sql-migrate v1.7.0
32+
github.com/rubenv/sql-migrate v1.7.1
3333
github.com/sirupsen/logrus v1.9.3
34-
github.com/spf13/cast v1.7.0
35-
github.com/spf13/cobra v1.8.1
34+
github.com/spf13/cast v1.7.1
35+
github.com/spf13/cobra v1.9.1
3636
github.com/spf13/viper v1.19.0
37-
github.com/stretchr/testify v1.9.0
37+
github.com/stretchr/testify v1.10.0
3838
github.com/stripe/stripe-go v70.15.0+incompatible
3939
github.com/volatiletech/null/v8 v8.1.2
40-
github.com/volatiletech/sqlboiler/v4 v4.16.2
41-
github.com/volatiletech/strmangle v0.0.6
40+
github.com/volatiletech/sqlboiler/v4 v4.18.0
41+
github.com/volatiletech/strmangle v0.0.8
4242
github.com/ybbus/jsonrpc/v2 v2.1.7
43-
golang.org/x/sync v0.8.0
43+
golang.org/x/sync v0.11.0
4444
)
4545

4646
require (
@@ -61,7 +61,7 @@ require (
6161
github.com/hashicorp/hcl v1.0.0 // indirect
6262
github.com/inconshreveable/mousetrap v1.1.0 // indirect
6363
github.com/johntdyer/slack-go v0.0.0-20230314151037-c5bf334f9b6e // indirect
64-
github.com/klauspost/compress v1.17.9 // indirect
64+
github.com/klauspost/compress v1.17.11 // indirect
6565
github.com/lbryio/types v0.0.0-20220224142228-73610f6654a6 // indirect
6666
github.com/magiconair/properties v1.8.7 // indirect
6767
github.com/mattn/go-colorable v0.1.13 // indirect
@@ -70,7 +70,7 @@ require (
7070
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
7171
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
7272
github.com/prometheus/client_model v0.6.1 // indirect
73-
github.com/prometheus/common v0.55.0 // indirect
73+
github.com/prometheus/common v0.62.0 // indirect
7474
github.com/prometheus/procfs v0.15.1 // indirect
7575
github.com/robfig/cron/v3 v3.0.1 // indirect
7676
github.com/sagikazarmark/locafero v0.4.0 // indirect
@@ -79,19 +79,19 @@ require (
7979
github.com/slack-go/slack v0.12.1 // indirect
8080
github.com/sourcegraph/conc v0.3.0 // indirect
8181
github.com/spf13/afero v1.11.0 // indirect
82-
github.com/spf13/pflag v1.0.5 // indirect
82+
github.com/spf13/pflag v1.0.6 // indirect
8383
github.com/subosito/gotenv v1.6.0 // indirect
8484
github.com/volatiletech/inflect v0.0.1 // indirect
8585
github.com/volatiletech/randomize v0.0.1 // indirect
8686
go.uber.org/atomic v1.10.0 // indirect
8787
go.uber.org/multierr v1.9.0 // indirect
88-
golang.org/x/crypto v0.25.0 // indirect
88+
golang.org/x/crypto v0.31.0 // indirect
8989
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
90-
golang.org/x/oauth2 v0.21.0 // indirect
91-
golang.org/x/sys v0.22.0 // indirect
92-
golang.org/x/text v0.16.0 // indirect
90+
golang.org/x/oauth2 v0.24.0 // indirect
91+
golang.org/x/sys v0.28.0 // indirect
92+
golang.org/x/text v0.21.0 // indirect
9393
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
94-
google.golang.org/protobuf v1.34.2 // indirect
94+
google.golang.org/protobuf v1.36.1 // indirect
9595
gopkg.in/ini.v1 v1.67.0 // indirect
9696
gopkg.in/nullbio/null.v6 v6.0.0-20161116030900-40264a2e6b79 // indirect
9797
gopkg.in/yaml.v3 v3.0.1 // indirect

go.sum

+41-37
Large diffs are not rendered by default.

migration/028_comment_tx_index.sql

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- +migrate Up
2+
-- +migrate StatementBegin
3+
ALTER TABLE comment add index idx_tx_id (tx_id);
4+
-- +migrate StatementEnd

server/lbry/apis.go

+42-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import (
44
"encoding/json"
55
"fmt"
66
"io"
7-
"io/ioutil"
87
"net/http"
98
"net/url"
109
"strconv"
10+
"time"
1111

1212
"github.com/OdyseeTeam/commentron/helper"
1313

@@ -75,7 +75,7 @@ func (c apiClient) CheckPerk(options CheckPerkOptions) (bool, error) {
7575
return false, errors.Err("No response from internal APIs")
7676
}
7777
defer helper.CloseBody(response.Body)
78-
b, err := ioutil.ReadAll(response.Body)
78+
b, err := io.ReadAll(response.Body)
7979
if err != nil {
8080
return false, errors.Err(err)
8181
}
@@ -91,6 +91,46 @@ func (c apiClient) CheckPerk(options CheckPerkOptions) (bool, error) {
9191
return perkRes.Data.HasAccess, nil
9292
}
9393

94+
type ArweavePaymentDetailsResponse struct {
95+
Amount uint64 `json:"amount"`
96+
Currency string `json:"currency"`
97+
Status string `json:"status"`
98+
UserId uint64 `json:"user_id"`
99+
ChannelClaimId string `json:"channel_claim_id"`
100+
TippedAt time.Time `json:"tipped_at"`
101+
}
102+
type apiArweavePaymentDetailsResponse struct {
103+
Success bool `json:"success"`
104+
Error interface{} `json:"error"`
105+
Data ArweavePaymentDetailsResponse `json:"data"`
106+
}
107+
108+
func (c apiClient) GetDetailsForTransaction(txId string) (*ArweavePaymentDetailsResponse, error) {
109+
const apiPath = "/arweave/payment/retrieve"
110+
client := http.Client{}
111+
form := make(url.Values)
112+
form.Set("auth_token", apiToken)
113+
form.Set("tx_id", txId)
114+
115+
response, err := client.PostForm(apiURL+apiPath, form)
116+
if err != nil {
117+
return nil, errors.Err(err)
118+
}
119+
defer helper.CloseBody(response.Body)
120+
121+
b, err := io.ReadAll(response.Body)
122+
if err != nil {
123+
return nil, errors.Err(err)
124+
}
125+
if response.StatusCode != http.StatusOK {
126+
return nil, errors.Err("API returned non-200 status code: %d", response.StatusCode)
127+
}
128+
var pr apiArweavePaymentDetailsResponse
129+
err = json.Unmarshal(b, &pr)
130+
131+
return &pr.Data, errors.Err(err)
132+
}
133+
94134
func notify(options NotifyOptions) error {
95135
const apiPath = "/event/comment"
96136
c := http.Client{}

server/lbry/client.go

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type CheckPerkOptions struct {
4747
type APIClient interface {
4848
Notify(NotifyOptions)
4949
CheckPerk(CheckPerkOptions) (bool, error)
50+
GetDetailsForTransaction(string) (*ArweavePaymentDetailsResponse, error)
5051
}
5152

5253
// Init initializes the configuration of the LBRY clients and allows for mock clients for testing
@@ -94,3 +95,7 @@ func (m *mockAPI) Notify(options NotifyOptions) {
9495
func (m *mockAPI) CheckPerk(options CheckPerkOptions) (bool, error) {
9596
return false, nil
9697
}
98+
99+
func (m *mockAPI) GetDetailsForTransaction(txId string) (*ArweavePaymentDetailsResponse, error) {
100+
return nil, nil
101+
}

server/lbry/validator.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"encoding/json"
1010
"encoding/pem"
1111
"fmt"
12-
"io/ioutil"
12+
"io"
1313
"math/big"
1414
"net/http"
1515
"net/url"
@@ -86,7 +86,7 @@ func getPublicKeyFromCQForChannel(channelClaimID string) ([]byte, error) {
8686
return nil, errors.Err(err)
8787
}
8888
defer helper.CloseBody(response.Body)
89-
b, err := ioutil.ReadAll(response.Body)
89+
b, err := io.ReadAll(response.Body)
9090
if err != nil {
9191
return nil, errors.Err(err)
9292
}
@@ -256,7 +256,7 @@ type publicKeyInfo struct {
256256
PublicKey asn1.BitString
257257
}
258258

259-
//why the hell are we reusing code from lbry.go instead of just using lbry.go??
259+
// why the hell are we reusing code from lbry.go instead of just using lbry.go??
260260
func getPublicKeyFromBytes(pubKeyBytes []byte) (*btcec.PublicKey, error) {
261261
if len(pubKeyBytes) == 33 {
262262
return btcec.ParsePubKey(pubKeyBytes, btcec.S256())

server/lbry/validator_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"encoding/hex"
77
"encoding/json"
88
"fmt"
9-
"io/ioutil"
9+
"io"
1010
"net/http"
1111
"net/url"
1212
"strconv"
@@ -158,7 +158,7 @@ func getResponseFromCQ(t *testing.T) {
158158
t.Fatal(err)
159159
}
160160
defer helper.CloseBody(response.Body)
161-
b, err := ioutil.ReadAll(response.Body)
161+
b, err := io.ReadAll(response.Body)
162162
if err != nil {
163163
t.Fatal(err)
164164
}

server/server.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
jsonmarshall "encoding/json"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"net/http"
99
"net/http/pprof"
1010
"os"
@@ -83,10 +83,10 @@ func Start() {
8383
func promRequestHandler(h http.Handler) http.Handler {
8484
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
8585
path := strings.TrimLeft(r.URL.Path, "/")
86-
body, _ := ioutil.ReadAll(r.Body)
87-
r.Body = ioutil.NopCloser(bytes.NewBuffer(body))
86+
body, _ := io.ReadAll(r.Body)
87+
r.Body = io.NopCloser(bytes.NewBuffer(body))
8888
codecRequest := json.NewCodec().NewRequest(r)
89-
r.Body = ioutil.NopCloser(bytes.NewBuffer(body))
89+
r.Body = io.NopCloser(bytes.NewBuffer(body))
9090
if method, err := codecRequest.Method(); err == nil {
9191
version, service, method := getCallDetails(path, method)
9292
metrics.UserLoadOverall.Inc()

0 commit comments

Comments
 (0)