Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement colonychain #38

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
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
16 changes: 12 additions & 4 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
## Type of this PR

> Select at least one type

- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Breaking change (fix or feature that would cause existing functionality to
not work as expected)
- [ ] Bug fix
- [ ] Dependency, Environment, Build related update
- [ ] Dependency, Environment, Build related update
- [ ] Documentation
- [ ] Other tiny fix
- [ ] Other tiny fix

## Describe your changes

## Issue ticket number and other helpful resource

## Checklist before requesting a review

- [ ] I have performed a self-review of my code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] Leave reference about this pull request, if exist (ex. discord message, google docs, etc)
- [ ] Leave reference about this pull request, if exist (ex. discord message,
google docs, etc)
- [ ] If it is a core feature, I have added thorough tests.

## Checklist after creating a pull request

- [ ] Mention reviews in discord channel directly
28 changes: 20 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,59 @@
# polkadot

## Reference
[Astar](https://docs.astar.network/)
[Polkadot](https://wiki.polkadot.network/)

[Astar](https://docs.astar.network/) [Polkadot](https://wiki.polkadot.network/)
[Substrate](https://docs.substrate.io/quick-start/)

## Run

### Build

```
cargo build --all
```

### Format

```
cargo +nightly fmt
```

### Lint

```
cargo clippy --all --all-targets --release
```

### Test

```
TEST_CONFIG=test_config_example.json cargo test --all
```

### Create new contract

```
cargo contract new [contract name]
```

### Build contract
To build a contract, execute this command with the path of `Cargo.toml` in the contract folder to build.
Build `simple_counter` with the cargo command and then upload and instantiate `.contract` file in `target/ink/your_contract/` on [Polkadot js Apps](https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Frococo-contracts-rpc.polkadot.io#/)

To build a contract, execute this command with the path of `Cargo.toml` in the
contract folder to build. Build `simple_counter` with the cargo command and then
upload and instantiate `.contract` file in `target/ink/your_contract/` on
[Polkadot js Apps](https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Frococo-contracts-rpc.polkadot.io#/)

```
cargo +nightly contract build --manifest-path ./simple_counter/Cargo.toml
```

### Test specific contract
To test specific contract, execute `cargo +nightly contract test` with `--manifest-path` with the path of `Cargo.toml`.
<br/>
e.g. Test `simple_counter` with this command.

To test specific contract, execute `cargo +nightly contract test` with
`--manifest-path` with the path of `Cargo.toml`.
<br/> e.g. Test `simple_counter` with this command.

```
cargo +nightly contract test --manifest-path ./simple_counter/Cargo.toml
```
```
1 change: 1 addition & 0 deletions colony-chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ serde = {version = "1.0", features = ["derive"]}
serde-tc = "0.3.3"
serde_json = {version = "1.0"}
tokio = {version = "1.0", features = ["full"]}
pdao-polkadot-interact = {path = "../interact"}
37 changes: 27 additions & 10 deletions colony-chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,55 @@ use async_trait::async_trait;
use pdao_beacon_chain_common::message as pbc_message;
use pdao_colony_common::*;
use pdao_colony_contract_common::*;
use pdao_polkadot_interact::{self, get_block, get_current_height};
use rust_decimal::prelude::*;
use rust_decimal_macros::dec;
use std::collections::HashMap;

pub struct Astar {}
pub struct Shiden {
pub full_node_uri: String,
pub http_server_url: String,
pub treasury_address: String,
pub light_client_address: String,
}

#[async_trait]
impl ColonyChain for Astar {
impl ColonyChain for Shiden {
async fn get_chain_name(&self) -> String {
"astar".to_owned()
"shiden".to_owned()
}

async fn get_last_block(&self) -> Result<Block, Error> {
Ok(Block {
height: 0,
timestamp: 0,
})
let height = get_current_height(&self.full_node_uri, &self.http_server_url)
.await
.unwrap()
.unwrap();
let timestamp = get_block(&self.full_node_uri, &self.http_server_url, height)
.await
.unwrap()
.timestamp;
Ok(Block { height, timestamp })
}

async fn check_connection(&self) -> Result<(), Error> {
Ok(())
let height = get_current_height(&self.full_node_uri, &self.http_server_url).await;
match height {
Ok(_height) => Ok(()),
Err(_error) => Err(Error::ConnectionError(
"Unable to get current height from full node".to_owned(),
)),
}
}

async fn get_contract_list(&self) -> Result<Vec<ContractInfo>, Error> {
Ok(vec![
ContractInfo {
address: "0xabcd".to_owned(),
address: self.treasury_address.clone(),
contract_type: ContractType::LightClient,
sequence: 0,
},
ContractInfo {
address: "0x1234".to_owned(),
address: self.light_client_address.clone(),
contract_type: ContractType::Treasury,
sequence: 0,
},
Expand Down
9 changes: 7 additions & 2 deletions colony-chain/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ async fn main() {
serde_tc::http::run_server(
port,
vec![(
"astar".to_owned(),
serde_tc::http::create_http_object(Arc::new(Astar {}) as Arc<dyn ColonyChain>),
"shiden".to_owned(),
serde_tc::http::create_http_object(Arc::new(Shiden {
full_node_uri: "".to_owned(),
http_server_url: "".to_owned(),
light_client_address: "".to_owned(),
treasury_address: "".to_owned(),
}) as Arc<dyn ColonyChain>),
)]
.into_iter()
.collect(),
Expand Down
12 changes: 6 additions & 6 deletions deno-http-server/abi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const ABI_PATH = {
SIMPLE_COUNTER: "./contracts/simple_counter.contract",
LIGHT_CLIENT: "./contracts/light_client.contract",
TREASURY: "./contracts/treasury",
} as const;
export type ABI_PATH_OPTIONS = typeof ABI_PATH[keyof typeof ABI_PATH];
SIMPLE_COUNTER: "./deno-http-server/contracts/simple_counter.contract",
LIGHT_CLIENT: "./deno-http-server/contracts/light_client.contract",
TREASURY: "./deno-http-server/contracts/treasury",
} as const;

export type ABI_PATH_OPTIONS = typeof ABI_PATH[keyof typeof ABI_PATH];
74 changes: 37 additions & 37 deletions deno-http-server/contract.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
export const CONTRACT = {
SIMPLE_COUNTER: "simple_counter",
LIGHT_CLIENT: "light_client",
TREASURY: "treasury",
} as const;
export type CONTRACT_OPTIONS = typeof CONTRACT[keyof typeof CONTRACT];
export const SIMPLE_COUNTER = {
GET_COUNT: "getCount",
GET_AUTH: "getAuth",
} as const;
export type SIMPLE_COUNTER_QUERY =
typeof SIMPLE_COUNTER[keyof typeof SIMPLE_COUNTER];
export const SIMPLE_COUNTER_TX = {
INIT: "init",
EXECUTE: "execute",
ADD_AUTH: "addAuth",
REMOVE_AUTH: "removeAuth",
INCREMENT: "increment",
DECREMENT: "decrement",
RESET: "reset",
} as const;
export type SIMPLE_COUNTER_TX_METHOD =
typeof SIMPLE_COUNTER_TX[keyof typeof SIMPLE_COUNTER_TX];
export const LIGHT_CLIENT = {} as const;
export type LIGHT_CLIENT_QUERY = typeof LIGHT_CLIENT[keyof typeof LIGHT_CLIENT];
export const LIGHT_CLIENT_TX = {} as const;
export type LIGHT_CLIENT_TX_METHOD =
typeof LIGHT_CLIENT_TX[keyof typeof LIGHT_CLIENT_TX];
export const TREASURY = {} as const;
export type TREASURY_QUERY = typeof TREASURY[keyof typeof TREASURY];
export const TREASURY_TX = {} as const;
export type TREASURY_TX_METHOD = typeof TREASURY_TX[keyof typeof TREASURY_TX];
SIMPLE_COUNTER: "simple_counter",
LIGHT_CLIENT: "light_client",
TREASURY: "treasury",
} as const;
export type CONTRACT_OPTIONS = typeof CONTRACT[keyof typeof CONTRACT];

export const SIMPLE_COUNTER = {
GET_COUNT: "getCount",
GET_AUTH: "getAuth",
} as const;
export type SIMPLE_COUNTER_QUERY =
typeof SIMPLE_COUNTER[keyof typeof SIMPLE_COUNTER];

export const SIMPLE_COUNTER_TX = {
INIT: "init",
EXECUTE: "execute",
ADD_AUTH: "addAuth",
REMOVE_AUTH: "removeAuth",
INCREMENT: "increment",
DECREMENT: "decrement",
RESET: "reset",
} as const;
export type SIMPLE_COUNTER_TX_METHOD =
typeof SIMPLE_COUNTER_TX[keyof typeof SIMPLE_COUNTER_TX];

export const LIGHT_CLIENT = {} as const;
export type LIGHT_CLIENT_QUERY = typeof LIGHT_CLIENT[keyof typeof LIGHT_CLIENT];

export const LIGHT_CLIENT_TX = {} as const;
export type LIGHT_CLIENT_TX_METHOD =
typeof LIGHT_CLIENT_TX[keyof typeof LIGHT_CLIENT_TX];

export const TREASURY = {} as const;
export type TREASURY_QUERY = typeof TREASURY[keyof typeof TREASURY];

export const TREASURY_TX = {} as const;
export type TREASURY_TX_METHOD = typeof TREASURY_TX[keyof typeof TREASURY_TX];
46 changes: 23 additions & 23 deletions deno-http-server/enum.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
export const enum TESTNET_MNEMONIC {
ROCOCO =
"where sign course conduct include wide because skull boss slice close tomorrow",
SHIBUYA =
"acoustic satisfy keen evidence hat citizen version magic nuclear misery invest tag",
}
export const enum RPC_ENDPOINT {
ROCOCO = "wss://rococo-contracts-rpc.polkadot.io:443",
SHIBUYA = "wss://shibuya-rpc.dwellir.com:443",
}
export const enum SS58_FORMAT {
POLKADOT = 0,
KUSAMA = 2,
SHIBUYA = 5,
DEFAULT = 42,
}
export const enum DECIMAL_PLACE_FROM_PLANCK {
POLKADOT = 10,
ROCOCO = 12,
SHIBUYA = 18,
}
ROCOCO =
"where sign course conduct include wide because skull boss slice close tomorrow",
SHIBUYA =
"acoustic satisfy keen evidence hat citizen version magic nuclear misery invest tag",
}

export const enum RPC_ENDPOINT {
ROCOCO = "wss://rococo-contracts-rpc.polkadot.io:443",
SHIBUYA = "wss://shibuya-rpc.dwellir.com:443",
}

export const enum SS58_FORMAT {
POLKADOT = 0,
KUSAMA = 2,
SHIBUYA = 5,
DEFAULT = 42,
}

export const enum DECIMAL_PLACE_FROM_PLANCK {
POLKADOT = 10,
ROCOCO = 12,
SHIBUYA = 18,
}
Loading