-
Notifications
You must be signed in to change notification settings - Fork 251
Implement solana cross contract calls without return values #407
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
Conversation
Now the instruction data includes multiple accounts. This makes it possible to call a Solang contract with multiple accounts, and automatically the right account will be picked. Signed-off-by: Sean Young <[email protected]>
6720c44 to
459b023
Compare
To implement cross program calls in Solana, we need to use the eth abi encoder in a slightly different way. A builder-style interface is very suited for this, so we can emit parts in steps while maintaining some state. Signed-off-by: Sean Young <[email protected]>
ABI encoding has no side affects, so it should be an expression. This means it can take part in various optimization passes. Signed-off-by: Sean Young <[email protected]>
Ensure CI will catch if we start using features from newer versions. Signed-off-by: Sean Young <[email protected]>
Instr::ExternalCall does implicit ABI encoding for the arguments. Make Instr::ExternalCall just accept an encoded payload and do ABI encoding in an explicit expression. This has some advantages: - Makes it possible to run optimizing passes over the explicit ABI encoding expression - Make the emitting stage much simpler, and no longer aware of different external call types; it's just a single external call - ABI encoding for Solana cross contract calls are encoded slightly differently. This can now be handled during codegen. Signed-off-by: Sean Young <[email protected]>
b70fd91 to
5bba7a5
Compare
This is used for the builtin `bytes foo = abi.encodePacked("xyz", true);`,
and we want to re-use it to pack the instruction for Solana cross
program calls.
Note this fixes various endian problem with abi encoding, scale codec
or eth abi. The function selector should now have the correct type
`bytes4` rather than `uint32`.
Signed-off-by: Sean Young <[email protected]>
integration/solana/index.ts
Outdated
| const input: string = Web3EthAbi.encodeFunctionCall(abi, params); | ||
| const data = Buffer.concat([ | ||
| this.contractStorageAccount.publicKey.toBuffer(), | ||
| Buffer.from(input.substr(2), 'hex') |
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.
seems it is moved from #141. Wonder what 2 means 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.
Yes, you are right -- this could be a lot clearer. The problem is that web3-eth-abi returns the encoded data as a hex string starting with "0x". So, this strips the "0x" and then node's buffer can hex-decode it. I'll see how can I make this clearer.
We're stripping of the leading "0x", which is not clear. Replace this
with replace('0x', '') to improve readability.
Signed-off-by: Sean Young <[email protected]>
7568e7d to
f36abe7
Compare
No return data can be passed back yet, this will be implemented in another commit. Signed-off-by: Sean Young <[email protected]>
This modifies the instruction so that the public key for the called account is included.
Note this does not implement return values yet.