Coder Social home page Coder Social logo

Comments (2)

ivanschuetz avatar ivanschuetz commented on June 4, 2024

A partly "Rust specific" example:

LogicSignature is modeled after the algod REST API:

pub struct LogicSignature {
    #[serde(rename = "l")]
    pub logic: Vec<u8>,

    pub sig: Option<Signature>,
    pub msig: Option<MultisigSignature>,

    #[serde(rename = "arg")]
    pub args: Vec<Vec<u8>>,
}

this struct is used in the domain too, which isn't ideal. As far I understand having both sig and msig set is illegal (it at least fails the verification). A sum type would represent this better:

enum Sig {
    Sig(Signature),
    Msig(MultisigSignature),
}

New domain type:

pub struct LogicSignature {
    pub logic: Vec<u8>,
    pub sig: Option<Sig>,
    pub args: Vec<Vec<u8>>,
}

Now we can't have the illegal state. It could be expanded further, to not need an optional:

enum Sig {
    ContractAccount
    Sig(Signature),
    Msig(MultisigSignature),
}

pub struct LogicSignature {
    pub logic: Vec<u8>,
    pub sig: Sig,
    pub args: Vec<Vec<u8>>,
}

And now we can remove already almost half of the Java SDK's verification method and related Unit Tests

The problem with these type of changes is that e.g. Java doesn't have sum types, so they can't be proposed there. @manuelmauro thoughts?

from algonaut.

ivanschuetz avatar ivanschuetz commented on June 4, 2024

Cleared internally:

  • The SDK will prioritize idiomatic Rust.
  • For refactorings not related with above, we will submit issues to the Go SDK, when it's possible to keep the APIs similar.

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.