-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore!: support new encoding schema #2826
Changes from all commits
9bea8da
90e770a
9de7a60
73189e3
4aed148
2d20852
bab9581
818cf57
d3db561
5e77a5e
d5fb298
e6cc1df
bcadd20
dae1946
7cdbbd9
ddc259b
61bab02
c961194
0f4dd1a
0500627
7e0c424
42316f1
ca552b8
a5f7426
675f28f
97e653b
fbd64bd
5ed2872
fb274c5
773a72a
9007b12
1f273e7
803bde8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@fuel-ts/abi-typegen": minor | ||
"@fuel-ts/abi-coder": minor | ||
"fuels": minor | ||
--- | ||
|
||
chore!: support new encoding schema |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.62.0 | ||
git:esdrubal/abi_changes |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,10 @@ export const buildFromGitBranch = (branchName) => { | |
const stdioOpts = { stdio: 'inherit' }; | ||
|
||
if (existsSync(swayRepoDir)) { | ||
execSync(`cd ${swayRepoDir} && git fetch origin && git checkout ${branchName}`, stdioOpts); | ||
execSync( | ||
`cd ${swayRepoDir} && git fetch origin && git checkout ${branchName} && git reset --hard origin/${branchName}`, | ||
|
||
stdioOpts | ||
); | ||
execSync(`cd ${swayRepoDir} && cargo build`, stdioOpts); | ||
} else { | ||
execSync(`git clone --branch ${branchName} ${swayRepoUrl} ${swayRepoDir}`, stdioOpts); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,28 @@ | ||
import { ResolvedAbiType } from './ResolvedAbiType'; | ||
import type { ResolvedType } from './ResolvedType'; | ||
import type { DecodedValue, InputValue, Coder } from './encoding/coders/AbstractCoder'; | ||
import { getCoderForEncoding } from './encoding/strategies/getCoderForEncoding'; | ||
import type { EncodingOptions } from './types/EncodingOptions'; | ||
import type { JsonAbi, JsonAbiArgument } from './types/JsonAbi'; | ||
|
||
export abstract class AbiCoder { | ||
static getCoder( | ||
abi: JsonAbi, | ||
argument: JsonAbiArgument, | ||
type: ResolvedType, | ||
options: EncodingOptions = { | ||
padToWordSize: false, | ||
} | ||
): Coder { | ||
const resolvedAbiType = new ResolvedAbiType(abi, argument); | ||
return getCoderForEncoding(options.encoding)(resolvedAbiType, options); | ||
return getCoderForEncoding(options.encoding)(type, options); | ||
} | ||
|
||
static encode( | ||
abi: JsonAbi, | ||
argument: JsonAbiArgument, | ||
value: InputValue, | ||
options?: EncodingOptions | ||
) { | ||
return this.getCoder(abi, argument, options).encode(value); | ||
static encode(type: ResolvedType, value: InputValue, options?: EncodingOptions) { | ||
return this.getCoder(type, options).encode(value); | ||
} | ||
|
||
static decode( | ||
abi: JsonAbi, | ||
argument: JsonAbiArgument, | ||
type: ResolvedType, | ||
data: Uint8Array, | ||
offset: number, | ||
options?: EncodingOptions | ||
): [DecodedValue | undefined, number] { | ||
return this.getCoder(abi, argument, options).decode(data, offset) as [ | ||
DecodedValue | undefined, | ||
number, | ||
]; | ||
return this.getCoder(type, options).decode(data, offset) as [DecodedValue | undefined, number]; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO the intention here is just to expose the coding/coders.
AbiCoder
is the entry point and then interface is more opinionated on what is should be given. What is the reasoning here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reasoning is that I've changed the
AbiCoder
interface and had this failing, took a look and realized thatInterface
can be used here as well. If I had continued with usingAbiCoder
, I'd have to document whatResolvableType
andResolvedType
are, and those are definitely internal details that we don't want users to think about.IMO there is no need for us to provide two ways of interacting with an abi and
Interface
is sufficient, and if we go with the idea I proposed in #2826 (comment) we wouldn't lose any functionality.