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 logger #102

Open
wants to merge 1 commit 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
25 changes: 14 additions & 11 deletions examples/create_deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { SDL } from "@akashnetwork/akashjs/build/sdl";
import { getAkashTypeRegistry } from "@akashnetwork/akashjs/build/stargate";
import { CertificatePem } from "@akashnetwork/akashjs/build/certificates/certificate-manager/CertificateManager";
import { certificateManager } from "@akashnetwork/akashjs/build/certificates/certificate-manager";
import pino from "pino";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you install pino? I don't see it in the package.json

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe I forgot to add package.json while pushing the code.


const logger = pino();

// update this with your wallet mnemonic
const rpcEndpoint = "https://rpc.sandbox-01.aksh.pw";
Expand Down Expand Up @@ -100,7 +103,7 @@ async function walletFromMnemonic(mnemonic: string) {
try {
return await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, { prefix: "akash" });
} catch (error) {
console.error('Could not create wallet from mnemonic, have you updated "examples/fixtures/mnemonic.txt?"');
logger.error('Could not create wallet from mnemonic, have you updated "examples/fixtures/mnemonic.txt?"');
throw error;
}
}
Expand All @@ -111,7 +114,7 @@ async function createDeployment(sdl: SDL, wallet: DirectSecp256k1HdWallet, clien
const accounts = await wallet.getAccounts();

if (dseq != 0) {
console.log("Skipping deployment creation...");
logger.info("Skipping deployment creation...");
return {
id: {
owner: accounts[0].address,
Expand Down Expand Up @@ -179,12 +182,12 @@ async function fetchBid(dseq: number, owner: string) {
const timeout = 1000 * 60 * 5;

while (Date.now() - startTime < timeout) {
console.log("Fetching bids...");
logger.info("Fetching bids...");
await new Promise(resolve => setTimeout(resolve, 5000));
const bids = await client.Bids(request);

if (bids.bids.length > 0 && bids.bids[0].bid !== undefined) {
console.log("Bid fetched!");
logger.info("Bid fetched!");
return bids.bids[0].bid;
}

Expand Down Expand Up @@ -335,7 +338,7 @@ async function sendManifest(sdl: SDL, lease: Lease, wallet: DirectSecp256k1HdWal
res.on("error", reject);

res.on("data", chunk => {
console.log("Response:", chunk.toString());
logger.info("Response:", chunk.toString());
});

if (res.statusCode !== 200) {
Expand All @@ -355,7 +358,7 @@ async function sendManifest(sdl: SDL, lease: Lease, wallet: DirectSecp256k1HdWal
const timeout = 1000 * 60 * 10;

while (Date.now() - startTime < timeout) {
console.log("Waiting for deployment to start...");
logger.info("Waiting for deployment to start...");
const status = await queryLeaseStatus(lease, providerInfo.hostUri, certificate).catch(err => {
if (err.includes("Could not query lease status: 404")) {
return undefined;
Expand All @@ -367,7 +370,7 @@ async function sendManifest(sdl: SDL, lease: Lease, wallet: DirectSecp256k1HdWal
if (status) {
for (const [name, service] of Object.entries(status.services)) {
if (service.uris) {
console.log(`Service ${name} is available at:`, service.uris[0]);
logger.info(`Service ${name} is available at:`, service.uris[0]);
return;
}
}
Expand All @@ -383,14 +386,14 @@ async function sendManifest(sdl: SDL, lease: Lease, wallet: DirectSecp256k1HdWal
async function deploy() {
const { wallet, client, certificate, sdl } = await loadPrerequisites();

console.log("Creating deployment...");
logger.info("Creating deployment...");
const deployment = await createDeployment(sdl, wallet, client);

console.log("Creating lease...");
logger.info("Creating lease...");
const lease = await createLease(deployment, wallet, client);

console.log("Sending manifest...");
logger.info("Sending manifest...");
return await sendManifest(sdl, lease, wallet, certificate);
}

deploy().catch(console.error);
deploy().catch(logger.error);
5 changes: 4 additions & 1 deletion examples/details_of_single_provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { QueryClientImpl, QueryProviderRequest, QueryProviderResponse } from "@akashnetwork/akash-api/akash/provider/v1beta3";
import { getRpc } from "@akashnetwork/akashjs/build/rpc";
import pino from "pino";

const logger = pino();

async function main() {
const client = new QueryClientImpl(await getRpc("http://your.rpc.node"));
Expand All @@ -10,7 +13,7 @@ async function main() {
const providerResponse = await client.Provider(getProviderInfoRequest);
const data = QueryProviderResponse.toJSON(providerResponse);

console.log(data);
logger.info(data);
}

main();
5 changes: 4 additions & 1 deletion examples/estimate_gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { DirectSecp256k1HdWallet, Registry } from "@cosmjs/proto-signing";
import { SigningStargateClient } from "@cosmjs/stargate";
import { MsgCloseDeployment } from "@akashnetwork/akash-api/akash/deployment/v1beta3";
import { getAkashTypeRegistry, getTypeUrl } from "@akashnetwork/akashjs/build/stargate";
import pino from "pino";

const logger = pino();

async function main() {
const mnemonic = "your wallet mnemonic";
Expand Down Expand Up @@ -35,7 +38,7 @@ async function main() {

const gas = await client.simulate(account.address, [msgAny], "take down deployment");

console.log(gas);
logger.info(gas);
}

main();
5 changes: 4 additions & 1 deletion examples/get_deployments.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { QueryDeploymentsResponse, QueryDeploymentsRequest, QueryClientImpl } from "@akashnetwork/akash-api/akash/deployment/v1beta3";
import { getRpc } from "@akashnetwork/akashjs/build/rpc";
import pino from "pino";

const logger = pino();

async function main() {
const request = QueryDeploymentsRequest.fromJSON({
Expand All @@ -12,7 +15,7 @@ async function main() {
const response = await client.Deployments(request);
const data = QueryDeploymentsResponse.toJSON(response);

console.log(data);
logger.info(data);
}

main();
5 changes: 4 additions & 1 deletion examples/get_lease_status.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { QueryClientImpl, QueryLeaseRequest, QueryLeaseResponse } from "@akashnetwork/akash-api/akash/market/v1beta4";
import { getRpc } from "@akashnetwork/akashjs/build/rpc";
import pino from "pino";

const logger = pino();

async function main() {
const client = new QueryClientImpl(await getRpc("http://your.rpc.node"));
Expand All @@ -17,7 +20,7 @@ async function main() {
const leaseStatusResponse = await client.Lease(getLeaseStatusRequest);
const data = QueryLeaseResponse.toJSON(leaseStatusResponse);

console.log(data);
logger.info(data);
}

main();
5 changes: 4 additions & 1 deletion examples/list_all_providers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { QueryClientImpl, QueryProvidersRequest, QueryProvidersResponse } from "@akashnetwork/akash-api/akash/provider/v1beta3";
import { getRpc } from "@akashnetwork/akashjs/build/rpc";
import pino from "pino";

const logger = pino();

async function main() {
const client = new QueryClientImpl(await getRpc("http://your.rpc.node"));
Expand All @@ -13,7 +16,7 @@ async function main() {
const providersResponse = await client.Providers(providersRequest);
const data = QueryProvidersResponse.toJSON(providersResponse);

console.log(data);
logger.info(data);
}

main();
6 changes: 5 additions & 1 deletion src/wallet/storage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import pino from 'pino';

const logger = pino();

/**
* This file fills keytar in browser, to use localStorage in place.
*/

export async function getPassword() {
console.log("keytar fill");
logger.info("keytar fill");
return "click harvest range include miss vessel permit kiss clarify now grocery assist";
}

Expand Down
12 changes: 8 additions & 4 deletions test.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
<button id="getCerts">Get Certs</button>

<script type="text/javascript">
console.log(akjs);
import pino from 'pino';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does that actually work?


const logger = pino();

logger.info(akjs);

const fn = async () => {
const certs = await akjs.certificate.createCertificate("akash12345");
Expand All @@ -27,7 +31,7 @@
document.querySelector("#privateKey").value = certs.privateKey;

window.addEventListener("DOMContentLoaded", async (event) => {
console.log("DOM fully loaded and parsed");
logger.info("DOM fully loaded and parsed");
chain = akjs.keplr.getChains().testnet;
signer = await akjs.keplr.getSigner(chain);
client = await akjs.keplr.get(chain, signer);
Expand All @@ -45,7 +49,7 @@
client
);
} catch (error) {
console.log(`Akash Transport : ${error.message}`);
logger.info(`Akash Transport : ${error.message}`);
}
});

Expand All @@ -58,7 +62,7 @@
})
);

console.log(certs);
logger.info(certs);
});
};

Expand Down
3 changes: 3 additions & 0 deletions tests/test_deployments.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import tap from "tap";
import pino from "pino";

import { testSnap } from "./util";

Expand All @@ -11,6 +12,8 @@ import {
QueryDeploymentsResponse
} from "@akashnetwork/akash-api/akash/deployment/v1beta3/query";

const logger = pino();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not needed


tap.test("Deployments: query deployment list with owner filter", async t => {
t.plan(1);

Expand Down