-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb_source.go
More file actions
49 lines (42 loc) · 1.09 KB
/
Copy pathweb_source.go
File metadata and controls
49 lines (42 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package chainalysis
import (
"encoding/json"
"io"
"net/http"
)
const DefaultWebSourceURL = "https://raw.githubusercontent.com/0xsequence/chainalysis/master/index/sanctioned_addresses.json"
type webSource struct {
source string
}
// NewWebSource creates a new web source, this is the default source for the chainalysis package
// it uses the index we have stored in index/sanctioned_addresses.json
func NewWebSource(opSourceURL ...string) IndexSource {
sourceURL := DefaultWebSourceURL
if len(opSourceURL) > 0 {
sourceURL = opSourceURL[0]
}
return &webSource{
source: sourceURL,
}
}
func (w *webSource) FetchSanctionedAddressEvents() ([]SanctionedAddressEvent, error) {
res, err := http.DefaultClient.Get(w.source)
if err != nil {
return nil, err
}
defer res.Body.Close()
buf, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}
events := []SanctionedAddressEvent{}
err = json.Unmarshal(buf, &events)
if err != nil {
return nil, err
}
return events, nil
}
// SetIndex is no-op for the web source
func (w *webSource) SetIndex([]SanctionedAddressEvent) error {
return nil
}