diff --git a/data-streams/streams-direct/api/internal/decoder.go b/data-streams/streams-direct/api/internal/decoder.go index dcdbe688..af38d3e4 100644 --- a/data-streams/streams-direct/api/internal/decoder.go +++ b/data-streams/streams-direct/api/internal/decoder.go @@ -126,4 +126,4 @@ func DecodeFullReportAndReportData(payload []byte) (*ReportWithContext, error) { } return result, nil -} \ No newline at end of file +} diff --git a/data-streams/streams-direct/api/main-multiple-feeds.go b/data-streams/streams-direct/api/main-multiple-feeds.go index 19c03dc3..57b09e77 100644 --- a/data-streams/streams-direct/api/main-multiple-feeds.go +++ b/data-streams/streams-direct/api/main-multiple-feeds.go @@ -9,69 +9,69 @@ import ( ) func main() { - // Ensure the correct number of arguments are provided - if len(os.Args) < 2 { - log.Fatalf("Usage: %s ...", os.Args[0]) - } + // Ensure the correct number of arguments are provided + if len(os.Args) < 2 { + log.Fatalf("Usage: %s ...", 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("------------------------------------------------") + } + } } diff --git a/data-streams/streams-direct/api/main-single-feed.go b/data-streams/streams-direct/api/main-single-feed.go index 2c12dd55..3e0ef102 100644 --- a/data-streams/streams-direct/api/main-single-feed.go +++ b/data-streams/streams-direct/api/main-single-feed.go @@ -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 ", os.Args[0]) - } + // Check if a feed ID has been provided as an argument + if len(os.Args) < 2 { + log.Fatalf("Usage: %s ", 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() + } } diff --git a/data-streams/streams-direct/websocket/client/clientWs.go b/data-streams/streams-direct/websocket/client/clientWs.go index 8d17155c..23250670 100644 --- a/data-streams/streams-direct/websocket/client/clientWs.go +++ b/data-streams/streams-direct/websocket/client/clientWs.go @@ -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{ @@ -165,4 +165,4 @@ func pingLoop(ctx context.Context, conn *websocket.Conn) { } } } -} \ No newline at end of file +} diff --git a/data-streams/streams-direct/websocket/decodeFullReportHex.go b/data-streams/streams-direct/websocket/decodeFullReportHex.go index 3bfb7e61..8a570b3b 100644 --- a/data-streams/streams-direct/websocket/decodeFullReportHex.go +++ b/data-streams/streams-direct/websocket/decodeFullReportHex.go @@ -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()) - } -} \ No newline at end of file + 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()) + } +} diff --git a/data-streams/streams-direct/websocket/internal/decoder.go b/data-streams/streams-direct/websocket/internal/decoder.go index dcdbe688..af38d3e4 100644 --- a/data-streams/streams-direct/websocket/internal/decoder.go +++ b/data-streams/streams-direct/websocket/internal/decoder.go @@ -126,4 +126,4 @@ func DecodeFullReportAndReportData(payload []byte) (*ReportWithContext, error) { } return result, nil -} \ No newline at end of file +} diff --git a/data-streams/streams-direct/websocket/main.go b/data-streams/streams-direct/websocket/main.go index 7df83a4f..e6be1eb5 100644 --- a/data-streams/streams-direct/websocket/main.go +++ b/data-streams/streams-direct/websocket/main.go @@ -10,16 +10,16 @@ import ( ) func main() { - if len(os.Args) < 2 { - log.Fatalf("Usage: %s ...", os.Args[0]) - } + if len(os.Args) < 2 { + log.Fatalf("Usage: %s ...", 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) + } } diff --git a/my-crypto-coin/cli/mcc/balances.go b/my-crypto-coin/cli/mcc/balances.go index 21b3510c..ab331114 100644 --- a/my-crypto-coin/cli/mcc/balances.go +++ b/my-crypto-coin/cli/mcc/balances.go @@ -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 { @@ -38,4 +39,4 @@ var balancesListCmd = &cobra.Command{ fmt.Println(fmt.Sprintf("%s: %d", account, balance)) } }, -} \ No newline at end of file +} diff --git a/my-crypto-coin/cli/mcc/main.go b/my-crypto-coin/cli/mcc/main.go index 968ae030..cb1cf32d 100644 --- a/my-crypto-coin/cli/mcc/main.go +++ b/my-crypto-coin/cli/mcc/main.go @@ -1,9 +1,10 @@ package main import ( - "github.com/spf13/cobra" - "os" "fmt" + "os" + + "github.com/spf13/cobra" ) func main() { @@ -23,4 +24,4 @@ func main() { fmt.Fprintln(os.Stderr, err) os.Exit(1) } -} \ No newline at end of file +} diff --git a/my-crypto-coin/cli/mcc/tx.go b/my-crypto-coin/cli/mcc/tx.go index c32a67f6..c4db46e2 100644 --- a/my-crypto-coin/cli/mcc/tx.go +++ b/my-crypto-coin/cli/mcc/tx.go @@ -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 txCmd() *cobra.Command { @@ -20,7 +21,6 @@ func txCmd() *cobra.Command { return txsCmd } - func newTxCmd() *cobra.Command { var cmd = &cobra.Command{ Use: "new", @@ -59,4 +59,4 @@ func newTxCmd() *cobra.Command { cmd.MarkFlagRequired("value") return cmd -} \ No newline at end of file +} diff --git a/my-crypto-coin/cli/mcc/version.go b/my-crypto-coin/cli/mcc/version.go index b8c9c6e5..208c6917 100644 --- a/my-crypto-coin/cli/mcc/version.go +++ b/my-crypto-coin/cli/mcc/version.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/spf13/cobra" ) @@ -16,4 +17,4 @@ var versionCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { fmt.Println(fmt.Sprintf("Version: %s.%s.%s-beta %s", Major, Minor, Fix, Verbal)) }, -} \ No newline at end of file +} diff --git a/my-crypto-coin/ledger/genesis.go b/my-crypto-coin/ledger/genesis.go index 35558ba5..4ba6b907 100644 --- a/my-crypto-coin/ledger/genesis.go +++ b/my-crypto-coin/ledger/genesis.go @@ -1,8 +1,8 @@ package ledger import ( - "io/ioutil" "encoding/json" + "io/ioutil" ) type Genesis struct { @@ -16,11 +16,11 @@ func loadGenesis(path string) (Genesis, error) { } var loadedGenesis Genesis - + err = json.Unmarshal(genesisFileContent, &loadedGenesis) if err != nil { return Genesis{}, err } return loadedGenesis, nil -} \ No newline at end of file +} diff --git a/my-crypto-coin/ledger/state.go b/my-crypto-coin/ledger/state.go index 354da110..b1b8b066 100644 --- a/my-crypto-coin/ledger/state.go +++ b/my-crypto-coin/ledger/state.go @@ -1,11 +1,11 @@ package ledger import ( + "bufio" + "encoding/json" "fmt" "os" "path/filepath" - "bufio" - "encoding/json" ) type State struct { @@ -15,8 +15,7 @@ type State struct { dbFile *os.File } - -func SyncState() (*State, error) { +func SyncState() (*State, error) { cwd, err := os.Getwd() if err != nil { return nil, err @@ -95,4 +94,4 @@ func (s *State) WriteToLedger(tx Tx) error { } return nil -} \ No newline at end of file +}