-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e5cbbf
commit cc2ecd1
Showing
7 changed files
with
200 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
v2 "github.com/Concordium/concordium-go-sdk/v2" | ||
"github.com/Concordium/concordium-go-sdk/v2/pb" | ||
) | ||
|
||
// This example retrieves and prints projected earliest wintime of a baker. | ||
func main() { | ||
client, err := v2.NewClient(v2.Config{NodeAddress: "node.testnet.concordium.com:20000"}) | ||
if err != nil { | ||
log.Fatalf("Failed to instantiate client, err: %v", err) | ||
} | ||
|
||
// sending empty context, can also use any other context instead. | ||
resp, err := client.GetBakerEarliestWinTime(context.TODO(), &pb.BakerId{ | ||
Value: 1, | ||
}) | ||
if err != nil { | ||
log.Fatalf("failed to get wintime, err: %v", err) | ||
} | ||
|
||
fmt.Println("wintime: ", resp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"log" | ||
|
||
v2 "github.com/Concordium/concordium-go-sdk/v2" | ||
) | ||
|
||
// This example retrieves and prints the info of the bakers in the reward period of a block. | ||
func main() { | ||
client, err := v2.NewClient(v2.Config{NodeAddress: "node.testnet.concordium.com:20000"}) | ||
if err != nil { | ||
log.Fatalf("Failed to instantiate client, err: %v", err) | ||
} | ||
|
||
// sending empty context, can also use any other context instead. | ||
stream, err := client.GetBakersRewardPeriod(context.TODO(), v2.BlockHashInputBest{}) | ||
if err != nil { | ||
log.Fatalf("failed to get BakerRewardPeriodInfos, err: %v", err) | ||
} | ||
|
||
for err == nil { | ||
bakerRewardPeriodInfo, err := stream.Recv() | ||
if err != nil { | ||
if err == io.EOF { | ||
// All BakerRewardPeriodInfo recieved. | ||
break | ||
} | ||
log.Fatalf("Could not receive BakerRewardPeriodInfo, err: %v", err) | ||
} | ||
fmt.Println("BakerRewardPeriodInfo: ", bakerRewardPeriodInfo) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
v2 "github.com/Concordium/concordium-go-sdk/v2" | ||
) | ||
|
||
// This example retrieves and prints the blockcertificates of a non-genesis block. | ||
func main() { | ||
client, err := v2.NewClient(v2.Config{NodeAddress: "node.testnet.concordium.com:20000"}) | ||
if err != nil { | ||
log.Fatalf("Failed to instantiate client, err: %v", err) | ||
} | ||
|
||
// sending empty context, can also use any other context instead. | ||
resp, err := client.GetBlockCertificates(context.TODO(), v2.BlockHashInputBest{}) | ||
if err != nil { | ||
log.Fatalf("failed to get certificates, err: %v", err) | ||
} | ||
|
||
fmt.Println("certificates: ", resp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
v2 "github.com/Concordium/concordium-go-sdk/v2" | ||
) | ||
|
||
// This example retrieves and prints the block hash of the first finalized block in a specific epoch. | ||
func main() { | ||
client, err := v2.NewClient(v2.Config{NodeAddress: "node.testnet.concordium.com:20000"}) | ||
if err != nil { | ||
log.Fatalf("Failed to instantiate client, err: %v", err) | ||
} | ||
|
||
// sending empty context, can also use any other context instead. | ||
resp, err := client.GetFirstBlockEpoch(context.TODO(), v2.EpochRequestBlockHash{ | ||
BlockHash: v2.BlockHashInputLastFinal{}, | ||
}) | ||
if err != nil { | ||
log.Fatalf("failed to get first block, err: %v", err) | ||
} | ||
|
||
fmt.Println("hash: ", resp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"log" | ||
|
||
v2 "github.com/Concordium/concordium-go-sdk/v2" | ||
) | ||
|
||
// This example retrieves and prints the bakers that won the lottery in a particular historical epoch. | ||
func main() { | ||
client, err := v2.NewClient(v2.Config{NodeAddress: "node.testnet.concordium.com:20000"}) | ||
if err != nil { | ||
log.Fatalf("Failed to instantiate client, err: %v", err) | ||
} | ||
|
||
// sending empty context, can also use any other context instead. | ||
stream, err := client.GetWinningBakersEpoch(context.TODO(), v2.EpochRequestRelativeEpoch{ | ||
GenesisIndex: v2.GenesisIndex{Value: 3}, | ||
Epoch: v2.Epoch{Value: 5}, | ||
}) | ||
if err != nil { | ||
log.Fatalf("failed to get winning bakers, err: %v", err) | ||
} | ||
|
||
for err == nil { | ||
winningBaker, err := stream.Recv() | ||
if err != nil { | ||
if err == io.EOF { | ||
// All WinningBakers recieved. | ||
break | ||
} | ||
log.Fatalf("Could not receive winning baker, err: %v", err) | ||
} | ||
fmt.Println("Winning baker: ", winningBaker) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters