Skip to content

Conversation

@seanyoung
Copy link
Contributor

@seanyoung seanyoung commented Apr 13, 2021

This modifies the instruction so that the public key for the called account is included.

Note this does not implement return values yet.

@seanyoung seanyoung marked this pull request as draft April 13, 2021 21:37
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]>
@seanyoung seanyoung force-pushed the solana branch 2 times, most recently from 6720c44 to 459b023 Compare April 14, 2021 13:13
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]>
@seanyoung seanyoung force-pushed the solana branch 2 times, most recently from b70fd91 to 5bba7a5 Compare April 16, 2021 09:56
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]>
const input: string = Web3EthAbi.encodeFunctionCall(abi, params);
const data = Buffer.concat([
this.contractStorageAccount.publicKey.toBuffer(),
Buffer.from(input.substr(2), 'hex')

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.

Copy link
Contributor Author

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]>
@seanyoung seanyoung force-pushed the solana branch 3 times, most recently from 7568e7d to f36abe7 Compare April 19, 2021 16:33
No return data can be passed back yet, this will be implemented
in another commit.

Signed-off-by: Sean Young <[email protected]>
@seanyoung seanyoung marked this pull request as ready for review April 19, 2021 17:29
@seanyoung seanyoung changed the title Implement solana cross contract calls Implement solana cross contract calls without return values Apr 19, 2021
@seanyoung seanyoung merged commit c1db5ea into hyperledger-solang:main Apr 19, 2021
@seanyoung seanyoung deleted the solana branch April 19, 2021 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants