Fixes for examples (#1408)
* Add various fixes for the examples * Add the workaround for proposals for `impl_version` 94 * TODO: fix `toPromise` issue for queries with RxJS
This commit is contained in:
committed by
Jaco Greeff
parent
7b56a52fc3
commit
e7f488ed89
@@ -9,7 +9,7 @@ async function main () {
|
|||||||
const api = await ApiPromise.create();
|
const api = await ApiPromise.create();
|
||||||
|
|
||||||
// Subscribe to chain updates and log the current block number on update.
|
// Subscribe to chain updates and log the current block number on update.
|
||||||
const unsubscribe = await api.rpc.chain.subscribeNewHead((header) => {
|
const unsubscribe = await api.rpc.chain.subscribeNewHeads((header) => {
|
||||||
console.log(`Chain is at block: #${header.number}`);
|
console.log(`Chain is at block: #${header.number}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -10,8 +10,7 @@
|
|||||||
"start": "node index.js"
|
"start": "node index.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@polkadot/api": "0.80.1",
|
"@polkadot/api": "*"
|
||||||
"@polkadot/keyring": "^0.93.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"rimraf": "^2.6.2"
|
"rimraf": "^2.6.2"
|
||||||
|
|||||||
@@ -25,9 +25,11 @@ async function main () {
|
|||||||
const keyring = testKeyring.default();
|
const keyring = testKeyring.default();
|
||||||
const adminPair = keyring.getPair(adminId.toString());
|
const adminPair = keyring.getPair(adminId.toString());
|
||||||
|
|
||||||
// Retrieve the runtime to upgrade to
|
// Retrieve the runtime to upgrade
|
||||||
const code = fs.readFileSync('./test.wasm').toString('hex');
|
const code = fs.readFileSync('./test.wasm').toString('hex');
|
||||||
const proposal = api.tx.consensus.setCode(`0x${code}`);
|
const proposal = api.tx.system && api.tx.system.setCode
|
||||||
|
? api.tx.system.setCode(`0x${code}`) // For newer versions of Substrate
|
||||||
|
: api.tx.consensus.setCode(`0x${code}`); // For previous versions
|
||||||
|
|
||||||
console.log(`Upgrading from ${adminId}, ${code.length / 2} bytes`);
|
console.log(`Upgrading from ${adminId}, ${code.length / 2} bytes`);
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ async function main () {
|
|||||||
new ApiRx().isReady
|
new ApiRx().isReady
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap((api) =>
|
switchMap((api) =>
|
||||||
api.rpc.chain.subscribeNewHead()
|
api.rpc.chain.subscribeNewHeads()
|
||||||
))
|
))
|
||||||
.subscribe((header) => {
|
.subscribe((header) => {
|
||||||
console.log(`Chain is at block: #${header.number}`);
|
console.log(`Chain is at block: #${header.number}`);
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ async function main () {
|
|||||||
pairwise()
|
pairwise()
|
||||||
)
|
)
|
||||||
.subscribe((balance) => {
|
.subscribe((balance) => {
|
||||||
if (balance[0].eq('first')) {
|
if (balance[0] === 'first') {
|
||||||
// Now we know that if the previous value emitted as balance[0] is `first`,
|
// Now we know that if the previous value emitted as balance[0] is `first`,
|
||||||
// then balance[1] is the initial value of Alice account.
|
// then balance[1] is the initial value of Alice account.
|
||||||
console.log(`Alice ${Alice} has a balance of ${balance[1]}`);
|
console.log(`Alice ${Alice} has a balance of ${balance[1]}`);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ async function main () {
|
|||||||
const subscription = new ApiRx().isReady
|
const subscription = new ApiRx().isReady
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap((api) =>
|
switchMap((api) =>
|
||||||
api.rpc.chain.subscribeNewHead()
|
api.rpc.chain.subscribeNewHeads()
|
||||||
))
|
))
|
||||||
.subscribe((header) => {
|
.subscribe((header) => {
|
||||||
console.log(`Chain is at block: #${header.number}`);
|
console.log(`Chain is at block: #${header.number}`);
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ async function main () {
|
|||||||
const api = await ApiRx.create().toPromise();
|
const api = await ApiRx.create().toPromise();
|
||||||
|
|
||||||
// Create an instance of the keyring
|
// Create an instance of the keyring
|
||||||
const keyring = new Keyring({ type: 's25519' });
|
const keyring = new Keyring({ type: 'sr25519' });
|
||||||
|
|
||||||
// Add Alice to our keyring (with the known seed for the account)
|
// Add Alice to our keyring (with the known seed for the account)
|
||||||
const alice = keyring.addFomUri('//Alice');
|
const alice = keyring.addFromUri('//Alice');
|
||||||
|
|
||||||
// Create a extrinsic, transferring 12345 units to Bob.
|
// Create a extrinsic, transferring 12345 units to Bob.
|
||||||
api.tx.balances
|
const subscription = api.tx.balances
|
||||||
// create transfer
|
// create transfer
|
||||||
.transfer(BOB, 12345)
|
.transfer(BOB, 12345)
|
||||||
// Sign and send the transcation
|
// Sign and send the transcation
|
||||||
@@ -27,10 +27,11 @@ async function main () {
|
|||||||
.subscribe(({ status }) => {
|
.subscribe(({ status }) => {
|
||||||
if (status.isFinalized) {
|
if (status.isFinalized) {
|
||||||
console.log(`Successful transfer of 12345 from Alice to Bob with hash ${status.asFinalized.toHex()}`);
|
console.log(`Successful transfer of 12345 from Alice to Bob with hash ${status.asFinalized.toHex()}`);
|
||||||
|
subscription.unsubscribe();
|
||||||
} else {
|
} else {
|
||||||
console.log(`Staus of transfer: ${status.type}`);
|
console.log(`Status of transfer: ${status.type}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
main().catch(console.error).finally(() => process.exit());
|
main().catch(console.error);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ async function main () {
|
|||||||
const api = await ApiRx.create({ provider }).toPromise();
|
const api = await ApiRx.create({ provider }).toPromise();
|
||||||
|
|
||||||
// Retrieve the upgrade key from the chain state
|
// Retrieve the upgrade key from the chain state
|
||||||
|
// TODO It seems like this promise doesn't resolve
|
||||||
const adminId = await api.query.sudo.key().toPromise();
|
const adminId = await api.query.sudo.key().toPromise();
|
||||||
|
|
||||||
// Find the actual keypair in the keyring (if this is an changed value, the key
|
// Find the actual keypair in the keyring (if this is an changed value, the key
|
||||||
|
|||||||
Reference in New Issue
Block a user