Skip to content

Commit

Permalink
Merge pull request #1134 from gluwa/update-testnet-2.222.1
Browse files Browse the repository at this point in the history
Update testnet branch
  • Loading branch information
nathanwhit committed Jun 15, 2023
2 parents 0cc83df + dabb9eb commit 84b2342
Show file tree
Hide file tree
Showing 27 changed files with 692 additions and 92 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ jobs:
- uses: actions/checkout@v3

- name: Set-Up
env:
HOMEBREW_NO_INSTALL_CLEANUP: true
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: true
run: |
brew update
brew install cmake openssl protobuf
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ jobs:
if: matrix.operating-system == 'ubuntu-22.04'
run: |
sudo apt-get update
sudo apt install -y cmake pkg-config libssl-dev git build-essential clang libclang-dev curl protobuf-compiler
sudo apt install -y cmake pkg-config libssl-dev git build-essential clang libclang-dev curl
- name: Install protobuf
uses: arduino/setup-protoc@v2

- name: Configure rustc version
shell: bash
Expand Down
26 changes: 13 additions & 13 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ members = [
"test/traced-test",
]

resolver = "2"

[workspace.package]
version = '2.222.0'
version = '2.222.1'
authors = ['Gluwa Inc.', 'Nathan Whitaker <nathan.whitaker@gluwa.com>']
edition = '2021'
license = 'Unlicense'
Expand Down
115 changes: 115 additions & 0 deletions chainspecs/posTestnetSpec.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion creditcoin-js/creditcoin.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion creditcoin-js/src/examples/setup-authority.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApiPromise } from '@polkadot/api';
import { KeyringPair } from '@polkadot/keyring/types';
import { addAuthorityAsync } from '../extrinsics/add-authority';
import { Option, Null, u64 } from '@polkadot/types';
import { Option, Null } from '@polkadot/types';

const AUTHORITY_PUBKEY = '0x0238bcdc4d9ab1ef09a2f18ea49e512aafabaab02d21a8c6ff7d2ecee1f2a34d';
export const AUTHORITY_SURI = 'version energy retire rely olympic figure shop stumble fence trust spider civil';
Expand Down
2 changes: 1 addition & 1 deletion node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {
}

pub fn testnet_config() -> Result<ChainSpec, String> {
ChainSpec::from_json_bytes(&include_bytes!("../../chainspecs/testnetSpec.json")[..])
ChainSpec::from_json_bytes(&include_bytes!("../../chainspecs/posTestnetSpec.json")[..])
}

pub fn mainnet_config() -> Result<ChainSpec, String> {
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
// the compatible custom types.
spec_version: 222,
impl_version: 0,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 11,
state_version: 1,
Expand Down
11 changes: 2 additions & 9 deletions scripts/cc-cli/src/commands/balance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Command, OptionValues } from "commander";
import { newApi } from "../api";
import { getBalance, printBalance } from "../utils/balance";
import { checkAddress } from "../utils/account";

export function makeBalanceCommand() {
const cmd = new Command("balance");
Expand All @@ -14,18 +15,10 @@ async function balanceAction(options: OptionValues) {
const { api } = await newApi(options.url);

// Check options
checkAddress(options);
checkAddress(options.address, api);

const balance = await getBalance(options.address, api);

printBalance(balance);

process.exit(0);
}

function checkAddress(options: OptionValues) {
if (!options.address) {
console.log("Must specify address to get balance of");
process.exit(0);
}
}
33 changes: 21 additions & 12 deletions scripts/cc-cli/src/commands/bond.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { Command, OptionValues } from "commander";
import { newApi } from "../api";
import { getSeedFromOptions, initKeyringPair } from "../utils/account";
import {
checkAddress,
getSeedFromOptions,
initKeyringPair,
} from "../utils/account";
import { bond, parseRewardDestination } from "../utils/bond";
import { promptContinue } from "../utils/promptContinue";
import { Balance, getBalance } from "../utils/balance";
import { Balance, getBalance, toMicrounits } from "../utils/balance";

export function makeBondCommand() {
const cmd = new Command("bond");
Expand All @@ -19,25 +23,26 @@ export function makeBondCommand() {
"-r, --reward-destination [reward-destination]",
"Specify reward destination account to use for new account"
);
cmd.option(
"-x, --extra",
"Bond as extra, adding more funds to an existing bond"
);
cmd.action(bondAction);
return cmd;
}

async function bondAction(options: OptionValues) {
const { api } = await newApi(options.url);

// If no controller error and exit
if (!options.controller) {
console.log("Must specify controller address");
process.exit(1);
}
checkAddress(options.controller, api);

// If no amount error and exit
if (!options.amount || !parseInt(options.amount, 10)) {
console.log("Must specify amount to bond");
process.exit(1);
}

const { api } = await newApi(options.url);

const stashSeed = getSeedFromOptions(options);

// Check balance
Expand All @@ -58,21 +63,25 @@ async function bondAction(options: OptionValues) {

await promptContinue();

console.log("Extra: ", options.extra);

const bondTxHash = await bond(
stashSeed,
options.controller,
amount,
rewardDestination,
api
api,
options.extra
);

console.log("Bond transaction sent with hash:", bondTxHash);
process.exit(0);
}

function checkBalanceAgainstBondAmount(balance: Balance, amount: number) {
const amountInMicroUnits = BigInt(amount) * BigInt(1000000000000000000);
if (BigInt(balance.free) < amountInMicroUnits) {
throw new Error(`Insufficient funds to bond ${amountInMicroUnits}`);
if (balance.free.sub(balance.miscFrozen).lt(toMicrounits(amount))) {
throw new Error(
`Insufficient funds to bond ${toMicrounits(amount).toString()}`
);
}
}
71 changes: 71 additions & 0 deletions scripts/cc-cli/src/commands/bondExtra.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Command, OptionValues } from "commander";
import { newApi } from "../api";
import { getSeedFromOptions, initKeyringPair } from "../utils/account";
import { promptContinue } from "../utils/promptContinue";
import { Balance, getBalance, toMicrounits } from "../utils/balance";
import { bondExtra } from "../utils/bondExtra";
import { BN } from "creditcoin-js";

export function makeBondExtraCommand() {
const cmd = new Command("bond-extra");
cmd.description("Add CTC to an existing bond from a Stash account");
cmd.option("-a, --amount [amount]", "Amount to bond");
cmd.option("-s, --seed [seed phrase]", "Specify seed phrase to bond from");
cmd.option(
"-f, --file [file-name]",
"Specify file with seed phrase to bond from"
);
cmd.action(bondExtraAction);
return cmd;
}

async function bondExtraAction(options: OptionValues) {
// If no amount error and exit
if (!options.amount || !parseInt(options.amount, 10)) {
console.log("Must specify amount to bond");
process.exit(1);
}

const { api } = await newApi(options.url);

const stashSeed = getSeedFromOptions(options);

// Check balance
const stashKeyring = initKeyringPair(stashSeed);
const stashAddress = stashKeyring.address;
const balance = await getBalance(stashAddress, api);
const amount = parseInt(options.amount, 10);
checkBalanceAgainstBondAmount(balance, amount);

const alreadyBonded = checkIfAlreadyBonded(stashAddress, balance);
if (!alreadyBonded) {
console.log("Must already be bonded to use bond-extra, use bond instead");
process.exit(1);
}

console.log("Creating bond extra transaction...");
console.log("Amount:", parseInt(options.amount, 10));

await promptContinue();

const bondTxHash = await bondExtra(stashSeed, options.amount, api);

console.log("Bond transaction sent with hash:", bondTxHash);
process.exit(0);
}

function checkBalanceAgainstBondAmount(balance: Balance, amount: number) {
if (balance.free.sub(balance.miscFrozen).lt(toMicrounits(amount))) {
throw new Error(
`Insufficient funds to bond ${toMicrounits(amount).toString()}`
);
}
}

function checkIfAlreadyBonded(address: string, balance: Balance) {
if (balance.miscFrozen.gt(new BN(0))) {
return true;
} else {
return false;
}
}

0 comments on commit 84b2342

Please sign in to comment.