Skip to content

Commit

Permalink
Merge pull request #137 from Concordium/remove-v1
Browse files Browse the repository at this point in the history
Remove v1
  • Loading branch information
abizjak authored Nov 30, 2023
2 parents 2188ede + 3e37b76 commit 31e3ee5
Show file tree
Hide file tree
Showing 23 changed files with 282 additions and 2,701 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## Unreleased changes

- Remove the V1 API.
- Add `Display` implementation to `BlockIdentifier`.
- Add `Display` and `FromStr` implementations for `AccountIdentifier`.
- Rename `find_first_finalized_block_no_later_than` into
`find_first_finalized_block_no_earlier_than` since that correctly reflects its
semantics with respect to time and is much clearer.a

## 3.2.0

- The sdk now requires a `rustc` version at least 1.67 (Before it required version 1.66).
Expand Down
9 changes: 0 additions & 9 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(feature = "generate-protos")]
{
tonic_build::configure()
.build_client(true)
.build_server(false)
.out_dir("./src/v1/generated")
.compile(
&["concordium-base/concordium-grpc-api/concordium_p2p_rpc.proto"],
&["concordium-base/concordium-grpc-api/"],
)?;

tonic_build::configure()
.build_client(true)
.build_server(false)
Expand Down
39 changes: 20 additions & 19 deletions examples/balance-summary.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
#![allow(deprecated)]
//! List accounts with the most liquid balance, and total stake, total amount,
//! and total liquid amount of accounts. Additionally list contracts with at
//! most CCD owned.
use clap::AppSettings;
use concordium_rust_sdk::{
common::types::Amount,
endpoints::{self, Endpoint},
types::hashes::BlockHash,
v2::{self, BlockIdentifier},
};
use futures::Future;
use futures::{Future, TryStreamExt};
use structopt::StructOpt;

#[derive(StructOpt)]
struct App {
#[structopt(
long = "node",
help = "GRPC interface of the node.",
default_value = "http://localhost:10000"
help = "V2 GRPC interface of the node.",
default_value = "http://localhost:20000"
)]
endpoint: Endpoint,
endpoint: v2::Endpoint,
#[structopt(
long = "block",
long = "lastfinal",
help = "Block to query the data in. Defaults to last finalized block."
)]
block: Option<BlockHash>,
#[structopt(long = "token", help = "GRPC login token", default_value = "rpcadmin")]
token: String,
block: BlockIdentifier,
#[structopt(
long = "num",
help = "How many queries to make in parallel.",
Expand Down Expand Up @@ -92,14 +88,14 @@ async fn main() -> anyhow::Result<()> {
App::from_clap(&matches)
};

let mut client = endpoints::Client::connect(app.endpoint, app.token).await?;
let mut client = v2::Client::new(app.endpoint).await?;

let consensus_info = client.get_consensus_status().await?;

let block = app.block.unwrap_or(consensus_info.last_finalized_block);
let block = app.block;
println!("Listing accounts in block {}.", block);

let accounts = client.get_account_list(&block).await?;
let accounts_response = client.get_account_list(&block).await?;
let accounts = accounts_response.response.try_collect::<Vec<_>>().await?;
let block: BlockIdentifier = accounts_response.block_hash.into();

let total_accounts = accounts.len();
let closure_client = client.clone();
Expand All @@ -110,7 +106,7 @@ async fn main() -> anyhow::Result<()> {
let mut client = closure_client.clone();
async move {
let block = block;
let info = client.get_account_info(acc, &block).await?;
let info = client.get_account_info(&acc.into(), &block).await?.response;
let additional_stake = info
.account_stake
.map_or(Amount::zero(), |baker_delegator| {
Expand Down Expand Up @@ -166,14 +162,19 @@ async fn main() -> anyhow::Result<()> {

// Now also handle contracts.
let mut total_contract_amount = Amount::zero();
let contracts = client.get_instances(&block).await?;
let contracts = client
.get_instance_list(&block)
.await?
.response
.try_collect::<Vec<_>>()
.await?;
let mut cout = Vec::new();
for ccs in contracts.chunks(app.num).map(Vec::from) {
let mut handles = Vec::with_capacity(app.num);
for contract in ccs {
let mut client = client.clone();
handles.push(tokio::spawn(async move {
let info = client.get_instance_info(contract, &block).await?;
let info = client.get_instance_info(contract, &block).await?.response;
Ok::<_, anyhow::Error>((contract, info))
}));
}
Expand Down
94 changes: 0 additions & 94 deletions examples/basic-test.rs

This file was deleted.

20 changes: 11 additions & 9 deletions examples/collisions.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#![allow(deprecated)]
//! A simple script to check how many bytes in an address are needed to
//! distinguish accounts. The script gets the account list from the node.
use clap::AppSettings;
use concordium_rust_sdk::{
endpoints::{self, Endpoint},
id::types::AccountAddress,
v2::{self, BlockIdentifier},
};
use futures::TryStreamExt;
use structopt::StructOpt;

#[derive(StructOpt)]
struct App {
#[structopt(
long = "node",
help = "GRPC interface of the node.",
default_value = "http://localhost:10000"
default_value = "http://localhost:20000"
)]
endpoint: Endpoint,
endpoint: v2::Endpoint,
}

#[tokio::main(flavor = "multi_thread")]
Expand All @@ -26,12 +26,14 @@ async fn main() -> anyhow::Result<()> {
App::from_clap(&matches)
};

let mut client = endpoints::Client::connect(app.endpoint, "rpcadmin".to_string()).await?;
let mut client = v2::Client::new(app.endpoint).await?;

let consensus_info = client.get_consensus_status().await?;

let cb = consensus_info.best_block;
let bi = client.get_account_list(&cb).await?;
let bi = client
.get_account_list(BlockIdentifier::LastFinal)
.await?
.response
.try_collect::<Vec<_>>()
.await?;
println!("There are {} accounts.", bi.len());
for i in 0..32 {
let mut tmp = bi.clone();
Expand Down
3 changes: 1 addition & 2 deletions examples/create-initial-accounts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(deprecated)]
//! Generate initial account transactions and send them to the chain.
//! Generated account keys are stored in the `created-accounts` directory.
use anyhow::Context;
Expand Down Expand Up @@ -39,7 +38,7 @@ struct App {
#[structopt(
long = "node",
help = "GRPC interface of the node.",
default_value = "http://localhost:10000"
default_value = "http://localhost:20000"
)]
endpoint: Endpoint,
#[structopt(long = "identity-provider")]
Expand Down
17 changes: 8 additions & 9 deletions examples/init-update-contract.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(deprecated)]
//! Basic example that shows how to initialize and update a smart contract.
//!
//! In particular, it uses the "weather" contract which is part of the
Expand All @@ -14,9 +13,10 @@ use concordium_rust_sdk::{
},
types::{
smart_contracts::{ModuleReference, OwnedParameter},
transactions::{send, BlockItem, InitContractPayload, UpdateContractPayload},
transactions::{send, InitContractPayload, UpdateContractPayload},
AccountInfo, WalletAccount,
},
v2::{self, BlockIdentifier},
};
use std::path::PathBuf;
use structopt::*;
Expand All @@ -27,7 +27,7 @@ struct App {
#[structopt(
long = "node",
help = "GRPC interface of the node.",
default_value = "http://localhost:10000"
default_value = "http://localhost:20000"
)]
endpoint: endpoints::Endpoint,
#[structopt(long = "account", help = "Path to the account key file.")]
Expand Down Expand Up @@ -89,17 +89,17 @@ async fn main() -> anyhow::Result<()> {
App::from_clap(&matches)
};

let mut client = endpoints::Client::connect(app.endpoint, "rpcadmin").await?;
let mut client = v2::Client::new(app.endpoint).await?;

// load account keys and sender address from a file
let keys: WalletAccount =
WalletAccount::from_json_file(app.keys_path).context("Could not parse the keys file.")?;

let consensus_info = client.get_consensus_status().await?;
// Get the initial nonce at the last finalized block.
let acc_info: AccountInfo = client
.get_account_info(&keys.address, &consensus_info.last_finalized_block)
.await?;
.get_account_info(&keys.address.into(), BlockIdentifier::LastFinal)
.await?
.response;

let nonce = acc_info.account_nonce;
// set expiry to now + 5min
Expand Down Expand Up @@ -136,9 +136,8 @@ async fn main() -> anyhow::Result<()> {
}
};

let item = BlockItem::AccountTransaction(tx);
// submit the transaction to the chain
let transaction_hash = client.send_block_item(&item).await?;
let transaction_hash = client.send_account_transaction(tx).await?;
println!(
"Transaction {} submitted (nonce = {}).",
transaction_hash, nonce,
Expand Down
Loading

0 comments on commit 31e3ee5

Please sign in to comment.