Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data-streams/streams-direct/api/internal/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,4 @@ func DecodeFullReportAndReportData(payload []byte) (*ReportWithContext, error) {
}

return result, nil
}
}
102 changes: 51 additions & 51 deletions data-streams/streams-direct/api/main-multiple-feeds.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,69 +9,69 @@ import (
)

func main() {
// Ensure the correct number of arguments are provided
if len(os.Args) < 2 {
log.Fatalf("Usage: %s <feedID1> <feedID2> ...", os.Args[0])
}
// Ensure the correct number of arguments are provided
if len(os.Args) < 2 {
log.Fatalf("Usage: %s <feedID1> <feedID2> ...", os.Args[0])
}

// Retrieve the feed IDs from command line arguments
feedIds := os.Args[1:]
// Retrieve the feed IDs from command line arguments
feedIds := os.Args[1:]

// Fetch reports for all provided feed IDs
reports, err := client.FetchSingleReportManyFeeds(feedIds)
if err != nil {
log.Fatalf("Failed to fetch reports: %v", err)
}
// Fetch reports for all provided feed IDs
reports, err := client.FetchSingleReportManyFeeds(feedIds)
if err != nil {
log.Fatalf("Failed to fetch reports: %v", err)
}

// Slice to store decoded reports
var decodedReports []*internal.ReportWithContext
// Slice to store decoded reports
var decodedReports []*internal.ReportWithContext

// Process each report fetched
for index, report := range reports {
// Decode the full report data
decodedReport, err := internal.DecodeFullReportAndReportData(report.FullReport)
if err != nil {
log.Fatalf("Failed to decode report: %v", err)
}
decodedReports = append(decodedReports, decodedReport)
// Process each report fetched
for index, report := range reports {
// Decode the full report data
decodedReport, err := internal.DecodeFullReportAndReportData(report.FullReport)
if err != nil {
log.Fatalf("Failed to decode report: %v", err)
}
decodedReports = append(decodedReports, decodedReport)

// Print the full report in hex format as the payload
printPayload(report.FullReport, feedIds[index])
}
// Print the full report in hex format as the payload
printPayload(report.FullReport, feedIds[index])
}

// Print details of all decoded reports
printReportDetails(decodedReports)
// Print details of all decoded reports
printReportDetails(decodedReports)
}

// Helper function to print the full report (payload) in hex format
func printPayload(payload []byte, feedId string) {
fmt.Println("")
fmt.Printf("Payload for onchain verification for Feed ID %s\n", feedId)
fmt.Println("=============================================================")
fmt.Printf("Payload (hexadecimal): 0x%x\n", payload)
fmt.Println("-------------------------------------------------------------")
fmt.Println()
fmt.Println("")
fmt.Printf("Payload for onchain verification for Feed ID %s\n", feedId)
fmt.Println("=============================================================")
fmt.Printf("Payload (hexadecimal): 0x%x\n", payload)
fmt.Println("-------------------------------------------------------------")
fmt.Println()
}

// Helper function to print details of the decoded reports
func printReportDetails(reports []*internal.ReportWithContext) {
fmt.Println("")
fmt.Println("Report Details")
fmt.Println("==============")
for _, report := range reports {
fmt.Printf("Feed ID: %s\n", report.FeedId)
if report.V3Report != nil {
fmt.Println("Decoded V3 Report Details:")
fmt.Println("-------------------------")
fmt.Printf("Valid From Timestamp: %d\n", report.V3Report.ValidFromTimestamp)
fmt.Printf("Observations Timestamp: %d\n", report.V3Report.ObservationsTimestamp)
fmt.Printf("Native Fee: %s\n", report.V3Report.NativeFee.String())
fmt.Printf("Link Fee: %s\n", report.V3Report.LinkFee.String())
fmt.Printf("Expires At: %d\n", report.V3Report.ExpiresAt)
fmt.Printf("Benchmark Price: %s\n", report.V3Report.BenchmarkPrice.String())
fmt.Printf("Bid: %s\n", report.V3Report.Bid.String())
fmt.Printf("Ask: %s\n", report.V3Report.Ask.String())
fmt.Println("------------------------------------------------")
}
}
fmt.Println("")
fmt.Println("Report Details")
fmt.Println("==============")
for _, report := range reports {
fmt.Printf("Feed ID: %s\n", report.FeedId)
if report.V3Report != nil {
fmt.Println("Decoded V3 Report Details:")
fmt.Println("-------------------------")
fmt.Printf("Valid From Timestamp: %d\n", report.V3Report.ValidFromTimestamp)
fmt.Printf("Observations Timestamp: %d\n", report.V3Report.ObservationsTimestamp)
fmt.Printf("Native Fee: %s\n", report.V3Report.NativeFee.String())
fmt.Printf("Link Fee: %s\n", report.V3Report.LinkFee.String())
fmt.Printf("Expires At: %d\n", report.V3Report.ExpiresAt)
fmt.Printf("Benchmark Price: %s\n", report.V3Report.BenchmarkPrice.String())
fmt.Printf("Bid: %s\n", report.V3Report.Bid.String())
fmt.Printf("Ask: %s\n", report.V3Report.Ask.String())
fmt.Println("------------------------------------------------")
}
}
}
89 changes: 44 additions & 45 deletions data-streams/streams-direct/api/main-single-feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,63 +11,62 @@ import (
)

func main() {
// Check if a feed ID has been provided as an argument
if len(os.Args) < 2 {
log.Fatalf("Usage: %s <feedId>", os.Args[0])
}
// Check if a feed ID has been provided as an argument
if len(os.Args) < 2 {
log.Fatalf("Usage: %s <feedId>", os.Args[0])
}

// Retrieve the feedId from the CL arguments
feedId := os.Args[1]
// Retrieve the feedId from the CL arguments
feedId := os.Args[1]

// Fetch the report for the specified feedId
report, err := client.FetchSingleReportSingleFeed(feedId)
if err != nil {
log.Fatalf("Failed to fetch report: %v", err)
}
// Fetch the report for the specified feedId
report, err := client.FetchSingleReportSingleFeed(feedId)
if err != nil {
log.Fatalf("Failed to fetch report: %v", err)
}

// Decode the full report data
decodedReport, err := internal.DecodeFullReportAndReportData(report.FullReport)
if err != nil {
log.Fatalf("Failed to decode report: %v", err)
}
// Decode the full report data
decodedReport, err := internal.DecodeFullReportAndReportData(report.FullReport)
if err != nil {
log.Fatalf("Failed to decode report: %v", err)
}

// Print details of the decoded report
printReportDetails(decodedReport)
// Print details of the decoded report
printReportDetails(decodedReport)

// Print the full report in hex format as the payload
printPayload(report.FullReport)
// Print the full report in hex format as the payload
printPayload(report.FullReport)
}

// Helper function to print the full report (payload) in hex format
func printPayload(payload []byte) {
fmt.Println("")
fmt.Println("Payload for onchain verification")
fmt.Println("=========================================")
fmt.Printf("Payload (hexadecimal): 0x%x\n", payload) // Adding '0x' prefix for hexadecimal representation
fmt.Println("------------------------------------------------")
fmt.Println()
fmt.Println("")
fmt.Println("Payload for onchain verification")
fmt.Println("=========================================")
fmt.Printf("Payload (hexadecimal): 0x%x\n", payload) // Adding '0x' prefix for hexadecimal representation
fmt.Println("------------------------------------------------")
fmt.Println()
}


// Helper function to print details of the decoded report
func printReportDetails(report *internal.ReportWithContext) {
fmt.Println("")
fmt.Println("Report Details")
fmt.Println("==============")
fmt.Printf("Feed ID: %s\n", report.FeedId)
fmt.Println()
fmt.Println("")
fmt.Println("Report Details")
fmt.Println("==============")
fmt.Printf("Feed ID: %s\n", report.FeedId)
fmt.Println()

if report.V3Report != nil {
fmt.Println("Decoded V3 Report Details:")
fmt.Println("-------------------------")
fmt.Printf("Valid From Timestamp: %d\n", report.V3Report.ValidFromTimestamp)
fmt.Printf("Observations Timestamp: %d\n", report.V3Report.ObservationsTimestamp)
fmt.Printf("Native Fee: %s\n", report.V3Report.NativeFee.String())
fmt.Printf("Link Fee: %s\n", report.V3Report.LinkFee.String())
fmt.Printf("Expires At: %d\n", report.V3Report.ExpiresAt)
fmt.Printf("Benchmark Price: %s\n", report.V3Report.BenchmarkPrice.String())
fmt.Printf("Bid: %s\n", report.V3Report.Bid.String())
fmt.Printf("Ask: %s\n", report.V3Report.Ask.String())
fmt.Println()
}
if report.V3Report != nil {
fmt.Println("Decoded V3 Report Details:")
fmt.Println("-------------------------")
fmt.Printf("Valid From Timestamp: %d\n", report.V3Report.ValidFromTimestamp)
fmt.Printf("Observations Timestamp: %d\n", report.V3Report.ObservationsTimestamp)
fmt.Printf("Native Fee: %s\n", report.V3Report.NativeFee.String())
fmt.Printf("Link Fee: %s\n", report.V3Report.LinkFee.String())
fmt.Printf("Expires At: %d\n", report.V3Report.ExpiresAt)
fmt.Printf("Benchmark Price: %s\n", report.V3Report.BenchmarkPrice.String())
fmt.Printf("Bid: %s\n", report.V3Report.Bid.String())
fmt.Printf("Ask: %s\n", report.V3Report.Ask.String())
fmt.Println()
}
}
12 changes: 6 additions & 6 deletions data-streams/streams-direct/websocket/client/clientWs.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,16 @@ func ConnectAndListen(ctx context.Context, feedIds []string) error {

// openWebsocketConnection opens a WebSocket connection to the server.
func openWebsocketConnection(ctx context.Context, feedIds []string) (*websocket.Conn, error) {
baseUrl := os.Getenv("BASE_URL") // Example: https://ws.testnet-dataengine.chain.link
clientId := os.Getenv("CLIENT_ID") // Example: "00000000-0000-0000-0000-000000000000"
baseUrl := os.Getenv("BASE_URL") // Example: https://ws.testnet-dataengine.chain.link
clientId := os.Getenv("CLIENT_ID") // Example: "00000000-0000-0000-0000-000000000000"
userSecret := os.Getenv("CLIENT_SECRET") // Example: "your-secret"

if len(feedIds) == 0 {
return nil, fmt.Errorf("no feed ID(s) provided")
}
return nil, fmt.Errorf("no feed ID(s) provided")
}

params := url.Values{
"feedIDs": {strings.Join(feedIds, ",")},
"feedIDs": {strings.Join(feedIds, ",")},
}

reqURL := &url.URL{
Expand Down Expand Up @@ -165,4 +165,4 @@ func pingLoop(ctx context.Context, conn *websocket.Conn) {
}
}
}
}
}
48 changes: 24 additions & 24 deletions data-streams/streams-direct/websocket/decodeFullReportHex.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@ import (
)

func main() {
// Sample FullReport payload extracted from the WebSocket message as a hex string
fullReportHex := "00067f14c763070bec1de1118aceeed1546878ab24e3213de21127249adabcbd0000000000000000000000000000000000000000000000000000000011f0c90b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000240010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e000027bbaff688c906a3e20a34fe951715d1018d262a5b66e38eda027a674cd1b0000000000000000000000000000000000000000000000000000000065cdcd950000000000000000000000000000000000000000000000000000000065cdcd95000000000000000000000000000000000000000000000000000020b5e9c686e80000000000000000000000000000000000000000000000000011b8f926846fb80000000000000000000000000000000000000000000000000000000065cf1f15000000000000000000000000000000000000000000000096ba314c8f5ec2800000000000000000000000000000000000000000000000000000000000000000029c85f7bb779ce5316821a6efd3bdc843e32f1438bad24a6b269871ade0c166d2142574b78d7a75d3cb855e51caf9cb36e1d598b43c881989251bd2c450624a2600000000000000000000000000000000000000000000000000000000000000021c1e5c393a57a24f2c698e23c59e6a954a9ef006b63c7f58eeabdd0bbeff21e5353ddef53e9beb93f628cd23e2cc28750533f444559622640bcf7dcc935d66af"
// Sample FullReport payload extracted from the WebSocket message as a hex string
fullReportHex := "00067f14c763070bec1de1118aceeed1546878ab24e3213de21127249adabcbd0000000000000000000000000000000000000000000000000000000011f0c90b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000240010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e000027bbaff688c906a3e20a34fe951715d1018d262a5b66e38eda027a674cd1b0000000000000000000000000000000000000000000000000000000065cdcd950000000000000000000000000000000000000000000000000000000065cdcd95000000000000000000000000000000000000000000000000000020b5e9c686e80000000000000000000000000000000000000000000000000011b8f926846fb80000000000000000000000000000000000000000000000000000000065cf1f15000000000000000000000000000000000000000000000096ba314c8f5ec2800000000000000000000000000000000000000000000000000000000000000000029c85f7bb779ce5316821a6efd3bdc843e32f1438bad24a6b269871ade0c166d2142574b78d7a75d3cb855e51caf9cb36e1d598b43c881989251bd2c450624a2600000000000000000000000000000000000000000000000000000000000000021c1e5c393a57a24f2c698e23c59e6a954a9ef006b63c7f58eeabdd0bbeff21e5353ddef53e9beb93f628cd23e2cc28750533f444559622640bcf7dcc935d66af"

// Convert the hex string to a byte slice
fullReportPayload, err := hex.DecodeString(fullReportHex)
if err != nil {
log.Fatalf("Failed to decode hex string: %v", err)
}
// Convert the hex string to a byte slice
fullReportPayload, err := hex.DecodeString(fullReportHex)
if err != nil {
log.Fatalf("Failed to decode hex string: %v", err)
}

// Decode the full report
decodedReport, err := internal.DecodeFullReportAndReportData(fullReportPayload)
if err != nil {
log.Fatalf("Failed to decode report: %v", err)
}
// Decode the full report
decodedReport, err := internal.DecodeFullReportAndReportData(fullReportPayload)
if err != nil {
log.Fatalf("Failed to decode report: %v", err)
}

fmt.Printf("Decoded Report: %+v\n", decodedReport)
fmt.Printf("Decoded Report: %+v\n", decodedReport)

if decodedReport.FeedVersion == 3 && decodedReport.V3Report != nil {
fmt.Printf("Valid From Timestamp: %d\n", decodedReport.V3Report.ValidFromTimestamp)
fmt.Printf("Observations Timestamp: %d\n", decodedReport.V3Report.ObservationsTimestamp)
fmt.Printf("Native Fee: %s\n", decodedReport.V3Report.NativeFee.String())
fmt.Printf("Link Fee: %s\n", decodedReport.V3Report.LinkFee.String())
fmt.Printf("Expires At: %d\n", decodedReport.V3Report.ExpiresAt)
fmt.Printf("Benchmark Price: %s\n", decodedReport.V3Report.BenchmarkPrice.String())
fmt.Printf("Bid: %s\n", decodedReport.V3Report.Bid.String())
fmt.Printf("Ask: %s\n", decodedReport.V3Report.Ask.String())
}
}
if decodedReport.FeedVersion == 3 && decodedReport.V3Report != nil {
fmt.Printf("Valid From Timestamp: %d\n", decodedReport.V3Report.ValidFromTimestamp)
fmt.Printf("Observations Timestamp: %d\n", decodedReport.V3Report.ObservationsTimestamp)
fmt.Printf("Native Fee: %s\n", decodedReport.V3Report.NativeFee.String())
fmt.Printf("Link Fee: %s\n", decodedReport.V3Report.LinkFee.String())
fmt.Printf("Expires At: %d\n", decodedReport.V3Report.ExpiresAt)
fmt.Printf("Benchmark Price: %s\n", decodedReport.V3Report.BenchmarkPrice.String())
fmt.Printf("Bid: %s\n", decodedReport.V3Report.Bid.String())
fmt.Printf("Ask: %s\n", decodedReport.V3Report.Ask.String())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,4 @@ func DecodeFullReportAndReportData(payload []byte) (*ReportWithContext, error) {
}

return result, nil
}
}
18 changes: 9 additions & 9 deletions data-streams/streams-direct/websocket/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import (
)

func main() {
if len(os.Args) < 2 {
log.Fatalf("Usage: %s <feedID1> <feedID2> ...", os.Args[0])
}
if len(os.Args) < 2 {
log.Fatalf("Usage: %s <feedID1> <feedID2> ...", os.Args[0])
}

feedIds := os.Args[1:]
feedIds := os.Args[1:]

ctx := context.Background()
ctx := context.Background()

// Pass feed IDs to the ConnectAndListen function
if err := client.ConnectAndListen(ctx, feedIds); err != nil {
log.Fatalf("Error connecting and listening: %v", err)
}
// Pass feed IDs to the ConnectAndListen function
if err := client.ConnectAndListen(ctx, feedIds); err != nil {
log.Fatalf("Error connecting and listening: %v", err)
}
}
7 changes: 4 additions & 3 deletions my-crypto-coin/cli/mcc/balances.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package main

import (
"github.com/spf13/cobra"
"my-crypto-coin/ledger"
"fmt"
"my-crypto-coin/ledger"
"os"

"github.com/spf13/cobra"
)

func balancesCmd() *cobra.Command {
Expand Down Expand Up @@ -38,4 +39,4 @@ var balancesListCmd = &cobra.Command{
fmt.Println(fmt.Sprintf("%s: %d", account, balance))
}
},
}
}
7 changes: 4 additions & 3 deletions my-crypto-coin/cli/mcc/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package main

import (
"github.com/spf13/cobra"
"os"
"fmt"
"os"

"github.com/spf13/cobra"
)

func main() {
Expand All @@ -23,4 +24,4 @@ func main() {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
}
Loading