Giter VIP home page Giter VIP logo

Comments (4)

algoradam avatar algoradam commented on June 18, 2024 1

basics.ChecksumAddress doesn't need to exist; the checksumming functionality can be brought into the MarshalText / UnmarshalText / String methods of basics.Address. This should allow most of the code in inspect.go to be deleted.

For context, whenever we represent an address as text, we compute and append a checksum -- this lets us catch errors if someone mistypes an address. When using addresses internally we don't bother keeping around the checksum; for example, when sending a transaction over the wire, we don't include the checksum in the binary (msgpack) representation of the sender address. The checksum is cheap enough that it's fine to recompute it if we ever need to display an address to a user.
At one point we thought it would be a good idea to have separate types for the internal / external representations of addresses -- basics.Address and basics.ChecksumAddress. But this turns out to add boilerplate (have to cast to a ChecksumAddress whenever displaying address to user) and make it easy to accidentally display to the user a non-checksummed address (by forgetting the cast).

Whenever we're representing an address as text (and only when we're representing an address as text), we want a checksum. So there don't need to be two separate types -- calculating the checksum should just happen inside the MarshalText, UnmarshalText, and String methods of basics.Address. Then basics.ChecksumAddress can be removed and all uses of basics.ChecksumAddress in our codebase can be replaced with basics.Address.

inspect.go just makes types identical to other types defined elsewhere but with checksumAddress where other types have Address so that e.g., the sender address of a transaction will print with the checksum. If basics.Address had a String method that added the checksum then fmt.Printf("%v", transaction) would already include checksums and most of the boilerplate in inspect.go could be removed.

(As a sidenote, I think the multisig-related code in crypto.go might still require these boilerplate wrappers because multisigs in some places use crypto.PublicKey instead of basics.Address. Multisig internals definitely could use some cleaning-up, but that's out of scope of this particular issue.)

from go-algorand.

Vervious avatar Vervious commented on June 18, 2024

(not sure crypto.PublicKey is an issue - it's a fixed array? Can you elaborate)

from go-algorand.

algoradam avatar algoradam commented on June 18, 2024

crypto.PublicKey doesn't (and probably shoudln't) include base32 or checksum printing code.

Multisigs include crypto.PublicKeys instead of basics.Addresses because (among other reasons) the basics package imports the crypto package and so the crypto package can't import the basics package. Changing that is probably out of scope of this issue.

So inspect.go will probably still need to contain code to pretty-print multisigs. However, we should be able to get rid of the non-multisig boilerplate like inspectTransaction, inspectTxnHeader, inspectPaymentTxnFields, etc.

from go-algorand.

algoradam avatar algoradam commented on June 18, 2024

Fixed by PR #102 (thanks zacharyestep!)

from go-algorand.

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.