hyperledger-solang / solang

Solidity Compiler for Solana and Polkadot
https://solang.readthedocs.io/
Apache License 2.0
1.26k stars 210 forks source link

Can not pass array variable to `create_program_address()` #1662

Open YanhuiJessica opened 1 month ago

YanhuiJessica commented 1 month ago

Describe the bug

error: conversion from bytes[] to bytes[] not possible
  ┌─ test.sol:9:39
  │
9 │         return create_program_address(seeds, token);
  │

To Reproduce Compile the attached source code with solang compile --target solana test.sol

Expected behavior create_program_address() should be able to accept array variables.

Hyperledger Solang version v0.3.3

Include the complete solidity source code The following example is derived from the documentation.

import {create_program_address} from 'solana';
contract pda {
    address token = address"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
    function create_pda(bytes seed2) public returns (address) {
        bytes[] seeds = ["kabang", seed2];
        return create_program_address(seeds, token);
    }
}

image

YanhuiJessica commented 1 month ago

Same as try_find_program_address()

seanyoung commented 1 month ago

That does look like an issue. However, in the mean time you can do it like so:

import {create_program_address} from 'solana';
contract pda {
    address token = address"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
    function create_pda(bytes seed2) public returns (address) {
        return create_program_address(["kabang", seed2], token);
    }
}
YanhuiJessica commented 1 month ago

yeah, not a big issue. However, working with variables is sometimes more flexible.