FuelLabs / fuels-rs

Fuel Network Rust SDK
https://fuellabs.github.io/fuels-rs
Apache License 2.0
44.04k stars 1.34k forks source link

Create a `B512` type to match `std::b512::B512` #688

Closed nfurfaro closed 2 years ago

nfurfaro commented 2 years ago

This is implemented in Sway as:

pub struct B512 {
    bytes: [b256; 2],
}

I'm currently working around this by making contract functions accept 2 b256 values and constructing the B512 in sway.

arboleya commented 2 years ago

@luizstacio @digorithm Should I consider this type for the new ABI typegen?

Initially, I followed only the primitives listed here:

The only mention of B512 is under signature recovery:

nfurfaro commented 2 years ago

B512 is a stdlib type, like Address, EvmAddress, Option & Result. It seems that sooner or later, for every type added to std there will be a request to use that type in the SDK. Perhaps moving forward, as new types are proposed for std we can coordinate with the SDK teams to roll out support more in parallel?

arboleya commented 2 years ago

Interesting. I wasn't paying attention to this.

Are these stdlib types documented somewhere?

I found only this that points to this, but there's no mention to B512.

Anyway, I believe Rust and Typescript SDK differ in some aspects.

Perhaps @luizstacio or @digorithm can shine a light on this matter.

digorithm commented 2 years ago

Are these stdlib types documented somewhere?

@arboleya some are documented here.

In terms of actual implementation, it differs between the Rust and TS SDKs, in some aspects. For instance, Option and Result types are not generated in the Rust SDK because Rust natively has Option and Result, so the SDK basically "maps" the Option/Result from Sway to Option/Result from Rust. The TS SDK does something similar, but with different mappings/strategies (e.g. there's no Result<T> in Typescript).

Regarding this:

Should I consider this type for the new https://github.com/FuelLabs/fuels-ts/pull/570?

If this is where all the other Sway/std-lib types are handled, yes, B512 should be part of it!

arboleya commented 2 years ago

@arboleya some are documented here.

But there's no mention of B512 either. 🤔

I was trying to understand where I could get a list of all std types for easy referencing.

If this is where all the other Sway/std-lib types are handled, yes, B512 should be part of it!

Thank you, I'll move the topic to a dedicated issue on the fuels-ts.