Coder Social home page Coder Social logo

Comments (3)

ivanschuetz avatar ivanschuetz commented on June 16, 2024

Bringing up here again that this:

The current builders are minimal implementations of the pattern that do not apply any compile-time validation

is outdated. Our transaction builders were refactored to check for mandatory fields at compile time. The only remaining builders with the issue should be the algod/kmd/indexer builders, which have a total of 1 or 2 mandatory fields. Here we might need possibly just a factory (initializer that returns an error if e.g. the URL is incorrectly formatted) instead of the builder pattern.

from algonaut.

AlterionX avatar AlterionX commented on June 16, 2024

A slight suggestion: I think the default builder should just be a tight wrapper of the custom endpoint builder struct. Reasoning being -- creating a custom endpoint should be a strictly more powerful ability than creating the default endpoint. It might also help with the discovery of the custom endpoint builder.

from algonaut.

ivanschuetz avatar ivanschuetz commented on June 16, 2024

What about something like this:

#[derive(Default)]
pub struct AlgodBuilder {}

impl AlgodBuilder {
    pub fn with_token(url: &str, token: &str) -> Result<Algod, AlgonautError> {
        Self::with_headers(
            url,
            vec![("X-Algo-API-Token", &ApiToken::parse(token)?.to_string())],
        )
    }

    pub fn with_headers(url: &str, headers: Headers) -> Result<Algod, AlgonautError> {
        Ok(Algod::new(Client::new(url, headers)?))
    }
}

We could also remove AlgodBuilder and just add a convenience initializers to Algod.

The later would also simplify managing multiple versions - if there are new versions, we don't need to create multiple entry points / builders.

If the initialization becomes more complex later (unlikely?) we can consider re-adding the builder pattern. Currently it seems not justified.

from algonaut.

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.