Skip to content

Commit eb0f620

Browse files
authored
Merge pull request #1672 from statechannels/fildev-payment-client
Fildev demo
2 parents e311e2e + 6f04e00 commit eb0f620

File tree

32 files changed

+978
-325
lines changed

32 files changed

+978
-325
lines changed

.github/workflows/deploy-cloud-nodes.yml

+20-17
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ on:
44
workflow_dispatch:
55
inputs:
66
build-image:
7-
description: 'Build docker image'
7+
description: "Build docker image"
88
required: false
9-
default: 'true'
9+
default: "true"
1010
deploy-iris:
11-
description: 'Deploy Iris'
11+
description: "Deploy Iris"
1212
required: false
13-
default: 'true'
13+
default: "true"
1414
deploy-anthony:
15-
description: 'Deploy Anthony'
15+
description: "Deploy Anthony"
1616
required: false
17-
default: 'true'
17+
default: "true"
1818
deploy-brad:
19-
description: 'Deploy Brad'
19+
description: "Deploy Brad"
2020
required: false
21-
default: 'true'
21+
default: "true"
2222

2323
jobs:
2424
build-image:
@@ -53,9 +53,9 @@ jobs:
5353
SSH_PRIVATE_KEY: ${{ secrets.IRIS_SSH_PRIVATE_KEY }}
5454
SC_PK: ${{ secrets.IRIS_SC_PK }}
5555
CHAIN_PK: ${{ secrets.IRIS_CHAIN_PK }}
56-
NITRO_CONFIG_PATH: './nitro_config/iris.toml'
57-
DROPLET_IP: '67.207.88.72'
58-
NODE_NAME: 'nitro_iris'
56+
NITRO_CONFIG_PATH: "./nitro_config/iris.toml"
57+
DROPLET_IP: "67.207.88.72"
58+
NODE_NAME: "nitro_iris"
5959
run: |
6060
echo "$SSH_PRIVATE_KEY" > private_key.pem
6161
chmod 600 private_key.pem
@@ -71,6 +71,7 @@ jobs:
7171
-e SC_PK=$SC_PK \
7272
-e CHAIN_PK=$CHAIN_PK \
7373
-v /var/nitro_store:/app/data \
74+
-v /etc/letsencrypt:/app/certs \
7475
registry.digitalocean.com/magmo/go-nitro:latest
7576
ENDSSH
7677
rm private_key.pem
@@ -87,9 +88,9 @@ jobs:
8788
SSH_PRIVATE_KEY: ${{ secrets.ANTHONY_SSH_PRIVATE_KEY }}
8889
SC_PK: ${{ secrets.ANTHONY_SC_PK }}
8990
CHAIN_PK: ${{ secrets.ANTHONY_CHAIN_PK }}
90-
NITRO_CONFIG_PATH: './nitro_config/anthony.toml'
91-
DROPLET_IP: '134.122.114.102'
92-
NODE_NAME: 'nitro_anthony'
91+
NITRO_CONFIG_PATH: "./nitro_config/anthony.toml"
92+
DROPLET_IP: "134.122.114.102"
93+
NODE_NAME: "nitro_anthony"
9394
run: |
9495
echo "$SSH_PRIVATE_KEY" > private_key.pem
9596
chmod 600 private_key.pem
@@ -105,6 +106,7 @@ jobs:
105106
-e SC_PK=$SC_PK \
106107
-e CHAIN_PK=$CHAIN_PK \
107108
-v /var/nitro_store:/app/data \
109+
-v /etc/letsencrypt:/app/certs \
108110
registry.digitalocean.com/magmo/go-nitro:latest
109111
ENDSSH
110112
rm private_key.pem
@@ -121,9 +123,9 @@ jobs:
121123
SSH_PRIVATE_KEY: ${{ secrets.BRAD_SSH_PRIVATE_KEY }}
122124
SC_PK: ${{ secrets.BRAD_SC_PK }}
123125
CHAIN_PK: ${{ secrets.BRAD_CHAIN_PK }}
124-
NITRO_CONFIG_PATH: './nitro_config/brad.toml'
125-
DROPLET_IP: '192.81.214.172'
126-
NODE_NAME: 'nitro_brad'
126+
NITRO_CONFIG_PATH: "./nitro_config/brad.toml"
127+
DROPLET_IP: "192.81.214.172"
128+
NODE_NAME: "nitro_brad"
127129
run: |
128130
echo "$SSH_PRIVATE_KEY" > private_key.pem
129131
chmod 600 private_key.pem
@@ -139,6 +141,7 @@ jobs:
139141
-e SC_PK=$SC_PK \
140142
-e CHAIN_PK=$CHAIN_PK \
141143
-v /var/nitro_store:/app/data \
144+
-v /etc/letsencrypt:/app/certs \
142145
registry.digitalocean.com/magmo/go-nitro:latest
143146
ENDSSH
144147
rm private_key.pem

.github/workflows/deploy-patsy.yml

+15-8
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ on:
44
workflow_dispatch:
55
inputs:
66
build-image:
7-
description: 'Build docker image'
7+
description: "Build docker image"
88
required: false
9-
default: 'true'
9+
default: "true"
1010
deploy-patsy:
11-
description: 'Deploy Patsy'
11+
description: "Deploy Patsy"
1212
required: false
13-
default: 'true'
13+
default: "true"
1414

1515
jobs:
1616
build-image:
@@ -43,10 +43,13 @@ jobs:
4343
env:
4444
DO_API_KEY: ${{ secrets.DO_API_KEY }}}
4545
SSH_PRIVATE_KEY: ${{ secrets.PATSY_SSH_PRIVATE_KEY }}
46-
DROPLET_IP: '165.22.197.200'
47-
NAME: 'nitro-payment-proxy'
48-
NITRO_ENDPOINT: 'brad-node.statechannels.org:4005/api/v1'
49-
DESTINATION_URL: 'https://magmo.com'
46+
DROPLET_IP: "165.22.197.200"
47+
NAME: "nitro-payment-proxy"
48+
NITRO_ENDPOINT: "brad-node.statechannels.org:4005/api/v1"
49+
DESTINATION_URL: "https://core8.datasetcreators.com/"
50+
TLS_CERT_FILE: /app/certs/live/payment-proxy.statechannels.org/fullchain.pem
51+
TLS_KEY_FILE: /app/certs/live/payment-proxy.statechannels.org/privkey.pem
52+
PROXY_PORT: 443
5053
run: |
5154
echo "$SSH_PRIVATE_KEY" > private_key.pem
5255
chmod 600 private_key.pem
@@ -56,9 +59,13 @@ jobs:
5659
docker stop $NAME || true
5760
docker rm $NAME || true
5861
docker run --restart=unless-stopped -it -d --name $NAME \
62+
-v /etc/letsencrypt:/app/certs \
5963
-p 443:443 -p 80:80 -p 5511:5511 \
6064
-e NITRO_ENDPOINT=$NITRO_ENDPOINT \
6165
-e DESTINATION_URL=$DESTINATION_URL \
66+
-e TLS_CERT_FILE=$TLS_CERT_FILE \
67+
-e TLS_KEY_FILE=$TLS_KEY_FILE \
68+
-e PROXY_PORT=$PROXY_PORT \
6269
registry.digitalocean.com/magmo/nitro-payment-proxy:latest
6370
ENDSSH
6471
rm private_key.pem

cmd/sample-file-server/main.go

+35-28
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package main
22

33
import (
44
"fmt"
5+
"image"
6+
"image/color"
7+
"image/png"
58
"log"
6-
"math/rand"
79
"net/http"
810
"os"
911
"os/signal"
@@ -29,12 +31,7 @@ func main() {
2931
Value: 8088,
3032
Aliases: []string{"p"},
3133
},
32-
&cli.StringFlag{
33-
Name: FILE_URL,
34-
Usage: "Specifies the url to serve the file at.",
35-
Value: "/test.txt",
36-
Aliases: []string{"f"},
37-
},
34+
3835
&cli.UintFlag{
3936
Name: FILE_LENGTH,
4037
Usage: "Specifies the length of the file to serve.",
@@ -44,17 +41,22 @@ func main() {
4441
},
4542
Action: func(c *cli.Context) error {
4643
const (
47-
fileName = "test.txt"
44+
fileName = "test.png"
4845
)
4946

5047
fileContent := generateFileData(c.Int(FILE_LENGTH))
5148
filePath, cleanup := setupFile(fileName, fileContent)
5249
defer cleanup()
5350

54-
http.HandleFunc(c.String(FILE_URL), func(w http.ResponseWriter, r *http.Request) {
51+
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
5552
// Set the Content-Disposition header to suggest a filename
5653
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", fileName))
5754

55+
// Add CORS headers to allow all origins (*).
56+
w.Header().Set("Access-Control-Allow-Origin", "*")
57+
w.Header().Set("Access-Control-Allow-Headers", "*")
58+
w.Header().Set("Access-Control-Expose-Headers", "*")
59+
5860
http.ServeFile(w, r, filePath)
5961
})
6062

@@ -81,7 +83,7 @@ func waitForKillSignal() {
8183
}
8284

8385
// setupFile creates a file with the given name and content, and returns a cleanup function
84-
func setupFile(fileName string, fileContent string) (string, func()) {
86+
func setupFile(fileName string, fileContent *image.RGBA) (string, func()) {
8587
dataFolder, err := os.MkdirTemp("", "sample-file-server-*")
8688
if err != nil {
8789
panic(err)
@@ -94,11 +96,12 @@ func setupFile(fileName string, fileContent string) (string, func()) {
9496
}
9597
defer file.Close()
9698

97-
_, err = file.WriteString(fileContent)
98-
if err != nil {
99+
if err := png.Encode(file, fileContent); err != nil {
100+
fmt.Println("Failed to encode image:", err)
99101
os.Remove(filePath)
100102
panic(err)
101103
}
104+
102105
return filePath, func() {
103106
err := os.Remove(fileName)
104107
if err != nil {
@@ -108,22 +111,26 @@ func setupFile(fileName string, fileContent string) (string, func()) {
108111
}
109112

110113
// generateFileData generates a string of the given length composed of random words
111-
func generateFileData(length int) (fileData string) {
112-
if length < 10 {
113-
panic("file length must be at least 10")
114-
}
115-
wordSelection := []string{
116-
"Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf", "Hotel",
117-
"India", "Juliet", "Kilo", "Lima", "Mike", "November", "Oscar", "Papa",
118-
"Quebec", "Romeo", "Sierra", "Tango", "Uniform", "Victor", "Whiskey",
119-
"X-ray", "Yankee", "Zulu",
120-
}
121-
fileData = "START"
122-
// Continue adding words until we reach the desired length or beyond
123-
for len(fileData) < length {
124-
randomIndex := rand.Intn(len(wordSelection))
125-
fileData = fileData + " " + wordSelection[randomIndex]
114+
func generateFileData(length int) (img *image.RGBA) {
115+
// Define image dimensions
116+
width, height := length, length
117+
118+
// Create an empty RGBA image
119+
img = image.NewRGBA(image.Rect(0, 0, width, height))
120+
121+
// Fill the image with a gradient
122+
for y := 0; y < height; y++ {
123+
for x := 0; x < width; x++ {
124+
// Gradient: Horizontal red, Vertical blue
125+
c := color.RGBA{
126+
R: uint8(x * 255 / width),
127+
B: uint8(y * 255 / height),
128+
G: 0,
129+
A: 255, // Fully opaque
130+
}
131+
img.Set(x, y, c)
132+
}
126133
}
127134

128-
return fileData[:length-3] + "END"
135+
return img
129136
}

cmd/start-payment-proxy/main.go

+15
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ const (
1616
PROXY_ADDRESS = "proxyaddress"
1717
DESTINATION_URL = "destinationurl"
1818
COST_PER_BYTE = "costperbyte"
19+
20+
TLS_CERT_FILEPATH = "tlscertfilepath"
21+
TLS_KEY_FILEPATH = "tlskeyfilepath"
1922
)
2023

2124
func main() {
@@ -48,6 +51,16 @@ func main() {
4851
Value: 1,
4952
Aliases: []string{"c"},
5053
},
54+
&cli.StringFlag{
55+
Name: TLS_CERT_FILEPATH,
56+
Usage: "Filepath to the TLS certificate. If not specified, TLS will not be used.",
57+
Value: "",
58+
},
59+
&cli.StringFlag{
60+
Name: TLS_KEY_FILEPATH,
61+
Usage: "Filepath to the TLS private key. If not specified, TLS will not be used.",
62+
Value: "",
63+
},
5164
},
5265
Action: func(c *cli.Context) error {
5366
proxyEndpoint := c.String(PROXY_ADDRESS)
@@ -60,6 +73,8 @@ func main() {
6073
nitroEndpoint,
6174
c.String(DESTINATION_URL),
6275
c.Uint64(COST_PER_BYTE),
76+
c.String(TLS_CERT_FILEPATH),
77+
c.String(TLS_KEY_FILEPATH),
6378
)
6479

6580
return proxy.Start()

docker/nitro/anthony.toml

+7-4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ pk = ""
1111
# Chain Public Address: 0x56032FA02b2592338b9A42B1865d5a5BEEaF2B75
1212
chainpk = ""
1313

14-
naaddress = "0xe32d4B5C5a80660710f6a2aD3cB1c11664138F34"
15-
vpaaddress = "0x4D1a804e1cE383D75032C52878553212992C98D7"
16-
caaddress = "0x0C9D79725afc344A388045235CD0B23eA4f0E838"
14+
naaddress = "0xe1790ea824035184a3bf344e087fb61744992545"
15+
vpaaddress = "0x95EfacCb38106C249F5ddC25b71677d5aF6d31A0"
16+
caaddress = "0xe1790ea824035184a3bf344e087fb61744992545"
1717

1818
# RPC provider docs: https://lotus.filecoin.io/lotus/developers/glif-nodes/#testnet-endpoint
1919
chainurl = "wss://wss.calibration.node.glif.io/apigw/lotus/rpc/v0"
20-
chainstartblock = 909569
20+
chainstartblock = 915929
2121
chainauthtoken = ""
2222

2323
bootpeers = "/ip4/67.207.88.72/tcp/3005/p2p/16Uiu2HAmDQj9XnHPD1d4GzS1K3DhmM5Z1cSGLfVTwVcNVdEsAN3Q"
24+
25+
tlscertfilepath = "/app/certs/live/anthony-node.statechannels.org/fullchain.pem"
26+
tlskeyfilepath = "/app/certs/live/anthony-node.statechannels.org/privkey.pem"

docker/nitro/brad.toml

+7-4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ pk = ""
1111
# Chain Public Address: 0xB62da17fab129AD3DF8858B7B1a834e570b8eead
1212
chainpk = ""
1313

14-
naaddress = "0xe32d4B5C5a80660710f6a2aD3cB1c11664138F34"
15-
vpaaddress = "0x4D1a804e1cE383D75032C52878553212992C98D7"
16-
caaddress = "0x0C9D79725afc344A388045235CD0B23eA4f0E838"
14+
naaddress = "0xe1790ea824035184a3bf344e087fb61744992545"
15+
vpaaddress = "0x95EfacCb38106C249F5ddC25b71677d5aF6d31A0"
16+
caaddress = "0xe1790ea824035184a3bf344e087fb61744992545"
1717

1818
# RPC provider docs: https://lotus.filecoin.io/lotus/developers/glif-nodes/#testnet-endpoint
1919
chainurl = "wss://wss.calibration.node.glif.io/apigw/lotus/rpc/v0"
20-
chainstartblock = 909569
20+
chainstartblock = 915929
2121
chainauthtoken = ""
2222

2323
bootpeers = "/ip4/67.207.88.72/tcp/3005/p2p/16Uiu2HAmDQj9XnHPD1d4GzS1K3DhmM5Z1cSGLfVTwVcNVdEsAN3Q"
24+
25+
tlscertfilepath = "/app/certs/live/brad-node.statechannels.org/fullchain.pem"
26+
tlskeyfilepath = "/app/certs/live/brad-node.statechannels.org/privkey.pem"

docker/nitro/iris.toml

+7-4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ pk = ""
1111
# Chain Public Address: 0x16e43DDc5FE417046Da7A0C469cCD4DE6b4764fA
1212
chainpk = ""
1313

14-
naaddress = "0xe32d4B5C5a80660710f6a2aD3cB1c11664138F34"
15-
vpaaddress = "0x4D1a804e1cE383D75032C52878553212992C98D7"
16-
caaddress = "0x0C9D79725afc344A388045235CD0B23eA4f0E838"
14+
naaddress = "0xe1790ea824035184a3bf344e087fb61744992545"
15+
vpaaddress = "0x95EfacCb38106C249F5ddC25b71677d5aF6d31A0"
16+
caaddress = "0xe1790ea824035184a3bf344e087fb61744992545"
1717

1818
# RPC provider docs: https://lotus.filecoin.io/lotus/developers/glif-nodes/#testnet-endpoint
1919
chainurl = "wss://wss.calibration.node.glif.io/apigw/lotus/rpc/v0"
20-
chainstartblock = 908130
20+
chainstartblock = 915929
2121
chainauthtoken = ""
2222

2323
bootpeers = ""
24+
25+
tlscertfilepath = "/app/certs/live/iris-node.statechannels.org/fullchain.pem"
26+
tlskeyfilepath = "/app/certs/live/iris-node.statechannels.org/privkey.pem"

docker/paymentproxy/Dockerfile

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM golang:1.21-bullseye AS builder
22
WORKDIR /app
33
COPY . .
4-
COPY ./docker/local/config.toml .
4+
55
RUN go build -o proxy ./cmd/start-payment-proxy
66

77
FROM debian:bullseye-slim
@@ -16,6 +16,8 @@ ENV PROXY_PORT=5511
1616
ENV NITRO_ENDPOINT=host.docker.internal:4007/api/v1
1717
ENV DESTINATION_URL=http://host.docker.internal:8088
1818
ENV COST_PER_BYTE=1
19+
ENV TLS_CERT_FILE=""
20+
ENV TLS_KEY_FILE=""
1921

2022
EXPOSE $PROXY_PORT
21-
CMD ./proxy --nitroendpoint $NITRO_ENDPOINT --proxyaddress 0.0.0.0:$PROXY_PORT --destinationurl $DESTINATION_URL --costperbyte $COST_PER_BYTE
23+
CMD ./proxy --nitroendpoint $NITRO_ENDPOINT --proxyaddress 0.0.0.0:$PROXY_PORT --destinationurl $DESTINATION_URL --costperbyte $COST_PER_BYTE --tlscertfilepath $TLS_CERT_FILE --tlskeyfilepath $TLS_KEY_FILE

main.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,13 @@ func main() {
242242
if err != nil {
243243
return err
244244
}
245+
var cert tls.Certificate
245246

246-
cert, err := tls.LoadX509KeyPair(tlsCertFilepath, tlsKeyFilepath)
247-
if err != nil {
248-
panic(err)
247+
if tlsCertFilepath != "" && tlsKeyFilepath != "" {
248+
cert, err = tls.LoadX509KeyPair(tlsCertFilepath, tlsKeyFilepath)
249+
if err != nil {
250+
panic(err)
251+
}
249252
}
250253

251254
rpcServer, err := rpc.InitializeRpcServer(node, rpcPort, useNats, &cert)

0 commit comments

Comments
 (0)