Skip to content

Commit

Permalink
Merge pull request #19 from decentldotland/prep
Browse files Browse the repository at this point in the history
near: `n-view-state` atom
  • Loading branch information
charmful0x authored Dec 27, 2022
2 parents 3256a68 + 9931987 commit 96f4c9a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ molecules/
└── icp/
├── └── icp-auth
└── ton/
└── ton-auth
├── └── ton-auth
└── near/
└── n-view-state
└── ark/
├── ├── resolve
├── └── state
Expand All @@ -71,6 +73,7 @@ molecules/
| TRON (`trx`) | `trx.molecule.sh` | `trx-auth` | 🟩 |
| Internet Protocol (`ICP`) | `icp.molecule.sh` | `icp-auth` | 🟩 |
| TON (`ton`) | `ton.molecule.sh` | `ton-auth` | 🟩 |
| NEAR (`near`) | `near.molecule.sh` | `n-view-state` | 🟩 |
| Ark Protocol (`ark`) | `ark.molecule.sh` | `state` `resolve` `soark/domain` | 🟩/🟨
| Randomization (`rand`) | `rand.molecule.sh` | `generate` | 🟩/🟨 |
| AI (`ai`) | `ai.molecule.sh` | `gpt3` | 🟩/🟨 |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "molecule",
"version": "0.1.4",
"version": "0.1.5",
"type": "module",
"description": "reusable EXM components and helper functions for a faster development",
"main": "./src/api.js",
Expand Down
16 changes: 16 additions & 0 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { isSubstrateSigner } from "./molecules/substrate/atoms/verifySigner.js";
import { isTrxSigner } from "./molecules/trx/atoms/verifySigner.js";
import { isIcpSigner } from "./molecules/icp/atoms/verifySigner.js";
import { isTonSigner } from "./molecules/ton/atoms/verifySigner.js";
import { readNearOracleState } from "./molecules/near/atoms/read-contract.js";
import base64url from "base64url";

const app = express();
Expand Down Expand Up @@ -179,6 +180,21 @@ app.get("/ton-auth/:pubkey/:message/:signature", async (req, res) => {
}
});

app.get("/n-view-state/:network/:address", async (req, res) => {
try {
res.setHeader("Content-Type", "application/json");

assert.equal(checkSubdomain(req, "near"), true);
const { network, address } = req.params;
const response = await readNearOracleState(network, address);
res.send(response);
return;
} catch (error) {
res.send({ result: null});
return;
}
});

app.get("/generate/:min/:max", async (req, res) => {
try {
res.setHeader("Content-Type", "application/json");
Expand Down
29 changes: 29 additions & 0 deletions src/molecules/near/atoms/read-contract.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import axios from "axios";
import assert from "node:assert";

export async function readNearOracleState(network, contract_id) {
try {
assert.equal(["mainnet", "testnet"].includes(network), true);
const req = await axios.post(`https://rpc.${network}.near.org`, {
jsonrpc: "2.0",
id: "dontcare",
method: "query",
params: {
request_type: "view_state",
finality: "final",
account_id: contract_id,
prefix_base64: "",
},
});
const result = req.data?.result?.values;
for (const keypair of result) {
keypair["key"] = atob(keypair.key);
keypair["value"] = atob(keypair.value);
delete keypair["proof"];
}

return { result };
} catch (error) {
return { result: null };
}
}
1 change: 1 addition & 0 deletions src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const MOLECULES = [
"trx",
"icp",
"ton",
"near",
"substrate",
"rand",
];

0 comments on commit 96f4c9a

Please sign in to comment.