GithubHelp home page GithubHelp logo

Comments (2)

KwilLuke avatar KwilLuke commented on August 22, 2024

Hey @pkoch,

Thanks for opening an issue! I can definitely see why you would want to be able to control / omit the error message. And you are correct that is where the warning comes from.

The one concern I have with just omitting the warning altogether with chainId: "" is that, before submitting a transaction securely, a developer should know that they are using the correct chainId to prevent transaction forwarding (e.g. preventing a malicious node operator from taking a valid transaction on network A and submitting it on network B). So if someone sets an empty string as a placeholder but later forgets to properly set the chain id, we definitely want to warn them.

I think there are two other approaches we could take on this:

1. Optional params to .chainInfo() to disable warning

We could add an optional argument to the .chainInfo() method that makes the warning configurable. Eg:

interface ChainInfoOpts {
  disableWarning?: boolean;
}

public async chainInfo(opts?: ChainInfoOpts): Promise<GenericResponse<ChainInfo>> {
  const info = await this.client.chainInfo();

  if (!opts?.disableWarning && info.data?.chain_id !== this.chainId) {
    console.warn(
      `WARNING: Chain ID mismatch. Expected ${info.data?.chain_id}, got ${this.chainId}`
    );
  }

  return info;
}

2. Make warning respect config.logging argument

We can make the warning message respect the configuration on the config.logging property on the WebKwil Constructor. So the implementation would be:

public async chainInfo(): Promise<GenericResponse<ChainInfo>> {
    const info = await this.client.chainInfo();

    if (this.config.logging && info.data?.chain_id !== this.chainId) {
      this.config.logger!(
        `WARNING: Chain ID mismatch. Expected ${info.data?.chain_id}, got ${this.chainId}`
      );
    }

    return info;
  }

And then, you can turn this message on/off with:

new WebKwil({
    kwilProvider: "some_provider",
    chainId: "",
    logging: false / true
});

Thoughts on either of these approaches? I would probably lean towards option 1, but am open to ideas.

from kwil-js.

pkoch avatar pkoch commented on August 22, 2024

Thank you! <3

from kwil-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.