Skip to content
Merged
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 .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
cargo build --bin linera
cargo run --bin linera -- resource-control-policy --block 0.0000001
cargo run --bin linera -- resource-control-policy --block 0.000000
cargo run --bin linera -- faucet --amount 1000 --port 8079 a3edc33d8e951a1139333be8a4b56646b5598a8f51216e86592d881808972b07 &
cargo run --bin linera -- faucet --amount 1000 --port 8079 &
- name: Run the remote-net tests
run: |
cargo test -p linera-service remote_net_grpc --features remote-net
Expand Down
4 changes: 2 additions & 2 deletions CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -720,12 +720,12 @@ Create an unassigned key pair

Link an owner with a key pair in the wallet to a chain that was created for that owner

**Usage:** `linera assign --owner <OWNER> --message-id <MESSAGE_ID>`
**Usage:** `linera assign --owner <OWNER> --chain-id <CHAIN_ID>`

###### **Options:**

* `--owner <OWNER>` — The owner to assign
* `--message-id <MESSAGE_ID>` — The ID of the message that created the chain. (This uniquely describes the chain and where it was created.)
* `--chain-id <CHAIN_ID>` — The ID of the chain



Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ linera wallet init --faucet $FAUCET_URL
INFO1=($(linera wallet request-chain --faucet $FAUCET_URL))
INFO2=($(linera wallet request-chain --faucet $FAUCET_URL))
CHAIN1="${INFO1[0]}"
ACCOUNT1="${INFO1[3]}"
ACCOUNT1="${INFO1[2]}"
CHAIN2="${INFO2[0]}"
ACCOUNT2="${INFO2[3]}"
ACCOUNT2="${INFO2[2]}"

# Show the different chains tracked by the wallet.
linera wallet show
Expand Down
1 change: 1 addition & 0 deletions examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
resolver = "2"
members = [
"amm",
"counter",
"call-evm-counter",
"counter",
"counter-no-graphql",
"crowd-funding",
"ethereum-tracker",
"fungible",
"gen-nft",
"how-to/perform-http-requests",
"hex-game",
"how-to/perform-http-requests",
"llm",
"matching-engine",
"meta-counter",
Expand Down
6 changes: 3 additions & 3 deletions examples/amm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ INFO_2=($(linera wallet request-chain --faucet $FAUCET_URL))
CHAIN_AMM="${INFO_AMM[0]}"
CHAIN_1="${INFO_1[0]}"
CHAIN_2="${INFO_2[0]}"
OWNER_AMM="${INFO_AMM[3]}"
OWNER_1="${INFO_1[3]}"
OWNER_2="${INFO_2[3]}"
OWNER_AMM="${INFO_AMM[2]}"
OWNER_1="${INFO_1[2]}"
OWNER_2="${INFO_2[2]}"
```

Now we have to publish and create the fungible applications. The flag `--wait-for-outgoing-messages` waits until a quorum of validators has confirmed that all sent cross-chain messages have been delivered.
Expand Down
2 changes: 1 addition & 1 deletion examples/counter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ linera wallet init --faucet $FAUCET_URL

INFO_1=($(linera wallet request-chain --faucet $FAUCET_URL))
CHAIN_1="${INFO_1[0]}"
OWNER_1="${INFO_1[3]}"
OWNER_1="${INFO_1[2]}"
```

Now, compile the `counter` application WebAssembly binaries, publish and create an application instance.
Expand Down
4 changes: 2 additions & 2 deletions examples/crowd-funding/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ INFO_1=($(linera --with-wallet 1 wallet request-chain --faucet $FAUCET_URL))
INFO_2=($(linera --with-wallet 2 wallet request-chain --faucet $FAUCET_URL))
CHAIN_1="${INFO_1[0]}"
CHAIN_2="${INFO_2[0]}"
OWNER_1="${INFO_1[3]}"
OWNER_2="${INFO_2[3]}"
OWNER_1="${INFO_1[2]}"
OWNER_2="${INFO_2[2]}"
```

Note that `linera --with-wallet 1` is equivalent to `linera --wallet "$LINERA_WALLET_1"
Expand Down
4 changes: 2 additions & 2 deletions examples/fungible/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ linera wallet init --faucet $FAUCET_URL

INFO_1=($(linera wallet request-chain --faucet $FAUCET_URL))
CHAIN_1="${INFO_1[0]}"
OWNER_1="${INFO_1[3]}"
OWNER_1="${INFO_1[2]}"
INFO_2=($(linera wallet request-chain --faucet $FAUCET_URL))
CHAIN_2="${INFO_2[0]}"
OWNER_2="${INFO_2[3]}"
OWNER_2="${INFO_2[2]}"
```

Now, compile the `fungible` application WebAssembly binaries, and publish them as an application
Expand Down
4 changes: 2 additions & 2 deletions examples/gen-nft/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ INFO_1=($(linera wallet request-chain --faucet $FAUCET_URL))
INFO_2=($(linera wallet request-chain --faucet $FAUCET_URL))
CHAIN_1="${INFO_1[0]}"
CHAIN_2="${INFO_2[0]}"
OWNER_1="${INFO_1[3]}"
OWNER_2="${INFO_2[3]}"
OWNER_1="${INFO_1[2]}"
OWNER_2="${INFO_2[2]}"
```

Next, compile the `non-fungible` application WebAssembly binaries, and publish them as an application module:
Expand Down
1 change: 1 addition & 0 deletions examples/hex-game/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"

[dependencies]
async-graphql.workspace = true
bcs.workspace = true
linera-sdk.workspace = true
log.workspace = true
serde.workspace = true
Expand Down
17 changes: 8 additions & 9 deletions examples/hex-game/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ INFO_1=($(linera --with-wallet 1 wallet request-chain --faucet $FAUCET_URL))
INFO_2=($(linera --with-wallet 2 wallet request-chain --faucet $FAUCET_URL))
CHAIN_1="${INFO_1[0]}"
CHAIN_2="${INFO_2[0]}"
OWNER_1="${INFO_1[3]}"
OWNER_2="${INFO_2[3]}"
OWNER_1="${INFO_1[2]}"
OWNER_2="${INFO_2[2]}"
```

Note that `linera --with-wallet 1` or `linera -w1` is equivalent to `linera --wallet
Expand Down Expand Up @@ -123,25 +123,24 @@ query {
gameChains {
entry(key: "$OWNER_1") {
value {
messageId chainId
chainId
}
}
}
}
```

Set the `QUERY_RESULT` variable to have the result returned by the previous query, and `HEX_CHAIN` and `MESSAGE_ID` will be properly set for you.
Alternatively you can set the variables to the `chainId` and `messageId` values, respectively, returned by the previous query yourself.
Using the message ID, we can assign the new chain to the key in each wallet:
Set the `QUERY_RESULT` variable to have the result returned by the previous query, and `HEX_CHAIN` will be properly set for you.
Alternatively you can set the variable to the `chainId`, returned by the previous query yourself.
Using the chain ID, we can assign the new chain to the key in each wallet:

```bash
kill %% && sleep 1 # Kill the service so we can use CLI commands for wallet 0.

HEX_CHAIN=$(echo "$QUERY_RESULT" | jq -r '.gameChains.entry.value[0].chainId')
MESSAGE_ID=$(echo "$QUERY_RESULT" | jq -r '.gameChains.entry.value[0].messageId')

linera -w1 assign --owner $OWNER_1 --message-id $MESSAGE_ID
linera -w2 assign --owner $OWNER_2 --message-id $MESSAGE_ID
linera -w1 assign --owner $OWNER_1 --chain-id $HEX_CHAIN
linera -w2 assign --owner $OWNER_2 --chain-id $HEX_CHAIN

linera -w1 service --port 8080 &
linera -w2 service --port 8081 &
Expand Down
7 changes: 2 additions & 5 deletions examples/hex-game/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,14 @@ impl HexContract {
);
let app_id = self.runtime.application_id();
let permissions = ApplicationPermissions::new_single(app_id.forget_abi());
let (message_id, chain_id) = self.runtime.open_chain(ownership, permissions, fee_budget);
let chain_id = self.runtime.open_chain(ownership, permissions, fee_budget);
for owner in &players {
self.state
.game_chains
.get_mut_or_default(owner)
.await
.unwrap()
.insert(GameChain {
message_id,
chain_id,
});
.insert(GameChain { chain_id });
}
self.runtime.send_message(
chain_id,
Expand Down
4 changes: 1 addition & 3 deletions examples/hex-game/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ use std::collections::BTreeSet;
use async_graphql::SimpleObject;
use hex_game::{Board, Clock, Timeouts};
use linera_sdk::{
linera_base_types::{AccountOwner, ChainId, MessageId},
linera_base_types::{AccountOwner, ChainId},
views::{linera_views, MapView, RegisterView, RootView, ViewStorageContext},
};
use serde::{Deserialize, Serialize};

/// The IDs of a temporary chain for a single game of Hex.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize, SimpleObject)]
pub struct GameChain {
/// The ID of the `OpenChain` message that created the chain.
pub message_id: MessageId,
/// The ID of the temporary game chain itself.
pub chain_id: ChainId,
}
Expand Down
24 changes: 19 additions & 5 deletions examples/hex-game/tests/hex_game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use hex_game::{HexAbi, Operation, Timeouts};
use linera_sdk::{
linera_base_types::{
AccountSecretKey, Amount, ChainDescription, Secp256k1SecretKey, TimeDelta,
AccountSecretKey, Amount, BlobType, ChainDescription, Secp256k1SecretKey, TimeDelta,
},
test::{ActiveChain, QueryOutcome, TestValidator},
};
Expand All @@ -34,8 +34,15 @@ async fn hex_game() {
.await;

let block = certificate.inner().block();
let message_id = block.message_id_for_operation(0, 0).unwrap();
let description = ChainDescription::Child(message_id);
let description = block
.created_blobs()
.into_iter()
.filter_map(|(blob_id, blob)| {
(blob_id.blob_type == BlobType::ChainDescription)
.then(|| bcs::from_bytes::<ChainDescription>(blob.content().bytes()).unwrap())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the operation results instead, and make the operation return the child chain ID as a result? (Also below.)

})
.next()
.unwrap();
let mut chain = ActiveChain::new(key_pair1.copy(), description, validator);

chain
Expand Down Expand Up @@ -108,8 +115,15 @@ async fn hex_game_clock() {
.await;

let block = certificate.inner().block();
let message_id = block.message_id_for_operation(0, 0).unwrap();
let description = ChainDescription::Child(message_id);
let description = block
.created_blobs()
.into_iter()
.filter_map(|(blob_id, blob)| {
(blob_id.blob_type == BlobType::ChainDescription)
.then(|| bcs::from_bytes::<ChainDescription>(blob.content().bytes()).unwrap())
})
.next()
.unwrap();
let mut chain = ActiveChain::new(key_pair1.copy(), description, validator.clone());

chain
Expand Down
14 changes: 7 additions & 7 deletions examples/how-to/perform-http-requests/tests/http_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async fn service_query_performs_http_request() -> anyhow::Result<()> {
let port = http_server.port();
let url = format!("http://localhost:{port}/");

let (validator, application_id, chain) =
let (mut validator, application_id, chain) =
TestValidator::with_current_application::<Abi, _, _>(url, ()).await;

validator
Expand Down Expand Up @@ -89,7 +89,7 @@ async fn service_sends_valid_http_response_to_contract() -> anyhow::Result<()> {
let port = http_server.port();
let url = format!("http://localhost:{port}/");

let (validator, application_id, chain) =
let (mut validator, application_id, chain) =
TestValidator::with_current_application::<Abi, _, _>(url, ()).await;

validator
Expand Down Expand Up @@ -119,7 +119,7 @@ async fn contract_rejects_invalid_http_response_from_service() {
let port = http_server.port();
let url = format!("http://localhost:{port}/");

let (validator, application_id, chain) =
let (mut validator, application_id, chain) =
TestValidator::with_current_application::<Abi, _, _>(url.clone(), ()).await;

validator
Expand Down Expand Up @@ -151,7 +151,7 @@ async fn contract_accepts_valid_http_response_it_obtains_by_itself() -> anyhow::
let port = http_server.port();
let url = format!("http://localhost:{port}/");

let (validator, application_id, chain) =
let (mut validator, application_id, chain) =
TestValidator::with_current_application::<Abi, _, _>(url, ()).await;

validator
Expand Down Expand Up @@ -181,7 +181,7 @@ async fn contract_rejects_invalid_http_response_it_obtains_by_itself() {
let port = http_server.port();
let url = format!("http://localhost:{port}/");

let (validator, application_id, chain) =
let (mut validator, application_id, chain) =
TestValidator::with_current_application::<Abi, _, _>(url, ()).await;

validator
Expand Down Expand Up @@ -214,7 +214,7 @@ async fn contract_accepts_valid_http_response_from_oracle() -> anyhow::Result<()
let port = http_server.port();
let url = format!("http://localhost:{port}/");

let (validator, application_id, chain) =
let (mut validator, application_id, chain) =
TestValidator::with_current_application::<Abi, _, _>(url, ()).await;

validator
Expand Down Expand Up @@ -245,7 +245,7 @@ async fn contract_rejects_invalid_http_response_from_oracle() {
let port = http_server.port();
let url = format!("http://localhost:{port}/");

let (validator, application_id, chain) =
let (mut validator, application_id, chain) =
TestValidator::with_current_application::<Abi, _, _>(url, ()).await;

validator
Expand Down
6 changes: 3 additions & 3 deletions examples/matching-engine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ INFO_3=($(linera wallet request-chain --faucet $FAUCET_URL))
CHAIN_1="${INFO_1[0]}"
CHAIN_2="${INFO_2[0]}"
CHAIN_3="${INFO_3[0]}"
OWNER_1="${INFO_1[3]}"
OWNER_2="${INFO_2[3]}"
OWNER_3="${INFO_3[3]}"
OWNER_1="${INFO_1[2]}"
OWNER_2="${INFO_2[2]}"
OWNER_3="${INFO_3[2]}"
```

Publish and create two `fungible` applications whose IDs will be used as a
Expand Down
4 changes: 2 additions & 2 deletions examples/native-fungible/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ INFO_1=($(linera wallet request-chain --faucet $FAUCET_URL))
INFO_2=($(linera wallet request-chain --faucet $FAUCET_URL))
CHAIN_1="${INFO_1[0]}"
CHAIN_2="${INFO_2[0]}"
OWNER_1="${INFO_1[3]}"
OWNER_2="${INFO_2[3]}"
OWNER_1="${INFO_1[2]}"
OWNER_2="${INFO_2[2]}"
```

Compile the `native-fungible` application WebAssembly binaries, and publish them as an application
Expand Down
10 changes: 5 additions & 5 deletions examples/native-fungible/tests/transfers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::collections::{BTreeMap, HashMap};

use fungible::{self, FungibleTokenAbi};
use linera_sdk::{
linera_base_types::{Account, AccountOwner, Amount, ChainId, CryptoHash},
linera_base_types::{Account, AccountOwner, Amount, CryptoHash},
test::{ActiveChain, Recipient, TestValidator},
};

Expand All @@ -28,7 +28,7 @@ async fn chain_balance_transfers() {
.await;

let transfer_amount = Amount::ONE;
let funding_chain = validator.get_chain(&ChainId::root(0));
let funding_chain = validator.get_chain(&validator.admin_chain_id());
let recipient = Recipient::chain(recipient_chain.id());

let transfer_certificate = funding_chain
Expand Down Expand Up @@ -62,7 +62,7 @@ async fn transfer_to_owner() {
.await;

let transfer_amount = Amount::from_tokens(2);
let funding_chain = validator.get_chain(&ChainId::root(0));
let funding_chain = validator.get_chain(&validator.admin_chain_id());
let owner = AccountOwner::from(CryptoHash::test_hash("owner"));
let account = Account::new(recipient_chain.id(), owner);
let recipient = Recipient::Account(account);
Expand Down Expand Up @@ -98,7 +98,7 @@ async fn transfer_to_multiple_owners() {

let number_of_owners = 10;
let transfer_amounts = (1..=number_of_owners).map(Amount::from_tokens);
let funding_chain = validator.get_chain(&ChainId::root(0));
let funding_chain = validator.get_chain(&validator.admin_chain_id());

let account_owners = (1..=number_of_owners)
.map(|index| AccountOwner::from(CryptoHash::test_hash(format!("owner{index}"))))
Expand Down Expand Up @@ -146,7 +146,7 @@ async fn emptied_account_disappears_from_queries() {
.await;

let transfer_amount = Amount::from_tokens(100);
let funding_chain = validator.get_chain(&ChainId::root(0));
let funding_chain = validator.get_chain(&validator.admin_chain_id());

let owner = AccountOwner::from(recipient_chain.public_key());
let recipient = Recipient::Account(Account::new(recipient_chain.id(), owner));
Expand Down
4 changes: 2 additions & 2 deletions examples/non-fungible/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ INFO_1=($(linera wallet request-chain --faucet $FAUCET_URL))
INFO_2=($(linera wallet request-chain --faucet $FAUCET_URL))
CHAIN_1="${INFO_1[0]}"
CHAIN_2="${INFO_2[0]}"
OWNER_1="${INFO_1[3]}"
OWNER_2="${INFO_2[3]}"
OWNER_1="${INFO_1[2]}"
OWNER_2="${INFO_2[2]}"
```

```bash
Expand Down
Loading