Skip to content

Commit

Permalink
Merge pull request #15 from ideal-lab5/feat/17-refactor-create-prepar…
Browse files Browse the repository at this point in the history
…e-execute

feat: construct call with response data
  • Loading branch information
juangirini authored Oct 10, 2024
2 parents 41605d6 + 5fba13d commit d8d93e0
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 184 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Lint Check

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20'

- name: Install dependencies
run: npm install

- name: Run Prettier check
run: npx prettier --check .
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.vscode
dist
node_modules
package-lock.json
package-lock.json
mmr_store
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
12 changes: 12 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"printWidth": 80,
"trailingComma": "es5",
"useTabs": false,
"tabWidth": 2,
"semi": false,
"singleQuote": true,
"arrowParens": "always",
"quoteProps": "consistent",
"bracketSpacing": true,
"endOfLine": "auto"
}
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,40 @@ The Murmur Client depends on:
You need to configure an `axios` and a `polkadot-js` instances to be injected in the Murmur Client.

```javascript
import { ApiPromise, WsProvider, Keyring } from "@polkadot/api";
import { KeyringPair } from "@polkadot/keyring/types";
import axios from "axios";
import { MurmurClient } from "murmur.js";
import { ApiPromise, WsProvider, Keyring } from '@polkadot/api'
import { KeyringPair } from '@polkadot/keyring/types'
import axios from 'axios'
import { MurmurClient } from 'murmur.js'

/* Polkadot API initialization */
const provider = new WsProvider("ws://127.0.0.1:9944");
console.log("Provider initialized");
const api = await ApiPromise.create({ provider });
console.log("API initialized");
const provider = new WsProvider('ws://127.0.0.1:9944')
console.log('Provider initialized')
const api = await ApiPromise.create({ provider })
console.log('API initialized')

/* Axios initialization */
const httpClient = axios.create({
baseURL: "https://api.example.com",
baseURL: 'https://api.example.com',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
});
})

/* Define the master account (optional, it falls back to `alice`) */
const keyring = new Keyring({ type: "sr25519" });
const alice = keyring.addFromUri("//Alice");
const keyring = new Keyring({ type: 'sr25519' })
const alice = keyring.addFromUri('//Alice')

/* MurmurClient initialization */
const murmurClient = new MurmurClient(httpClient, api, alice);
console.log("MurmurClient initialized");
const murmurClient = new MurmurClient(httpClient, api, alice)
console.log('MurmurClient initialized')

// Use the MurmurClient instance to make requests
murmurClient
.authenticate("username", "password")
.authenticate('username', 'password')
.then((response) => {
console.log(response);
console.log(response)
})
.catch((error) => {
console.error(error);
});
console.error(error)
})
```
42 changes: 21 additions & 21 deletions examples/create-execute/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
import { ApiPromise, WsProvider } from "@polkadot/api";
import axios from "axios";
import { MurmurClient } from "murmur.js";
import { ApiPromise, WsProvider } from '@polkadot/api'
import axios from 'axios'
import { MurmurClient } from 'murmur.js'

/* Polkadot API initialization */
const provider = new WsProvider("ws://127.0.0.1:9944");
console.log("Provider initialized");
const api = await ApiPromise.create({ provider });
console.log("API initialized");
const provider = new WsProvider('ws://127.0.0.1:9944')
console.log('Provider initialized')
const api = await ApiPromise.create({ provider })
console.log('API initialized')
// Retrieve the chain & node information via rpc calls
const [chain, nodeName, nodeVersion] = await Promise.all([
api.rpc.system.chain(),
api.rpc.system.name(),
api.rpc.system.version(),
]);
])
console.log(
`You are connected to chain ${chain} using ${nodeName} v${nodeVersion}`
);
)

/* Axios initialization */
const httpClient = axios.create({
baseURL: "http://127.0.0.1:8000",
baseURL: 'http://127.0.0.1:8000',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
});
})

/* MurmurClient initialization */
const murmurClient = new MurmurClient(httpClient, api);
console.log("MurmurClient initialized");
const murmurClient = new MurmurClient(httpClient, api)
console.log('MurmurClient initialized')

const loguinResult = await murmurClient.authenticate("admin", "password");
console.log(loguinResult);
const loguinResult = await murmurClient.authenticate('admin', 'password')
console.log(loguinResult)

await murmurClient.new(100, async (result: any) => {
console.log(`Tx Block Hash: ${result.status.asFinalized}`);
const bob = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty";
const call = api.tx.balances.transferAllowDeath(bob, 1000000000000);
await murmurClient.execute(call);
});
console.log(`Tx Block Hash: ${result.status.asFinalized}`)
const bob = '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty'
const call = api.tx.balances.transferAllowDeath(bob, 1000000000000)
await murmurClient.execute(call)
})
28 changes: 14 additions & 14 deletions examples/simple-connect/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import { ApiPromise, WsProvider } from "@polkadot/api";
import axios from "axios";
import { MurmurClient } from "murmur.js";
import { ApiPromise, WsProvider } from '@polkadot/api'
import axios from 'axios'
import { MurmurClient } from 'murmur.js'

/* Polkadot API initialization */
const provider = new WsProvider("ws://127.0.0.1:9944");
console.log("Provider initialized");
const api = await ApiPromise.create({ provider });
console.log("API initialized");
const provider = new WsProvider('ws://127.0.0.1:9944')
console.log('Provider initialized')
const api = await ApiPromise.create({ provider })
console.log('API initialized')
// Retrieve the chain & node information via rpc calls
const [chain, nodeName, nodeVersion] = await Promise.all([
api.rpc.system.chain(),
api.rpc.system.name(),
api.rpc.system.version(),
]);
])
console.log(
`You are connected to chain ${chain} using ${nodeName} v${nodeVersion}`
);
)

/* Axios initialization */
const httpClient = axios.create({
baseURL: "https://api.example.com",
baseURL: 'https://api.example.com',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
});
})

/* MurmurClient initialization */
new MurmurClient(httpClient, api);
console.log("MurmurClient initialized");
new MurmurClient(httpClient, api)
console.log('MurmurClient initialized')
17 changes: 16 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"main": "dist/index.js",
"scripts": {
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"prepare": "husky install"
},
"author": "Ideal Labs <[email protected]>",
"dependencies": {
Expand All @@ -16,6 +17,20 @@
},
"devDependencies": {
"@types/node": "^22.7.4",
"husky": "^8.0.0",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
"prettier-plugin-organize-imports": "^4.1.0",
"typescript": "^5.6.2"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,jsx,ts,tsx,json,md}": [
"prettier --write"
]
}
}
Loading

0 comments on commit d8d93e0

Please sign in to comment.