Skip to content
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

add test for encodeScriptFunctionByResolve call functionId 0x1::TransferScripts::batch_peer_to_peer_v2 #46

Closed
uvd opened this issue May 10, 2022 · 2 comments

Comments

@uvd
Copy link
Contributor

uvd commented May 10, 2022

my use this sdk will get error I'm not sure it‘s bug or I use wrong

starcoin.module.js:7951 Uncaught (in promise) TypeError: se[("serialize" + type.Vector)] is not a function
at starcoin.module.js:7951:1
at Array.forEach ()
at serializeWithType (starcoin.module.js:7945:1)
at starcoin.module.js:7974:1
at Array.map ()
at encodeScriptFunctionArgs (starcoin.module.js:7973:1)
at starcoin.module.js:7726:1
at async batchTransfer_v2 (stcWalletSdk.ts:118:1)

import {providers,utils,bcs} from "@starcoin/starcoin"
import { arrayify, hexlify } from '@ethersproject/bytes'

export interface BatchTransferInput{
    account:string
    amount:number
}

export async function batchTransfer_v2(input:BatchTransferInput[]){


    const toAddress:string[] = []
    const toAmount:number[] = []
    input.forEach((item)=>{
        toAddress.push(item.account)
        toAmount.push(1)
    })
    
    try {
        const functionId = '0x1::TransferScripts::batch_peer_to_peer_v2'
        const tyArgs = ['0x1::STC::STC']
        const args = [
            toAddress,
            toAmount
        ]
        const nodeUrl = nodeUrlMap[window.starcoin.networkVersion]
        window.console.info(functionId, tyArgs, args,nodeUrl)
        const scriptFunction = await utils.tx.encodeScriptFunctionByResolve(functionId, tyArgs, args,nodeUrl)
        window.console.log(scriptFunction)



        // Multiple BcsSerializers should be used in different closures, otherwise, the latter will be contaminated by the former.
        const payloadInHex = (function () {
            const se = new bcs.BcsSerializer()
            scriptFunction.serialize(se)
            return hexlify(se.getBytes())
        })()


        const txParams = {
            data: payloadInHex,

        }

        const expiredSecs = 10
        window.console.log({ expiredSecs })
        if (expiredSecs > 0) {
          //  txParams.expiredSecs = expiredSecs
        }

        const  starcoinProvider  = await getProvder();
        const transactionHash = await starcoinProvider.getSigner().sendUncheckedTransaction(txParams)
        window.console.log({ transactionHash })
    } catch (error) {

        throw error
    }


}
        const hash = "0x22a19240709CB17ec9523252AA17B997";
        const arr:BatchTransferInput[] = []
        arr.push({
            hash,
            amount:1
        })
@wk3368
Copy link
Collaborator

wk3368 commented May 12, 2022

root cause:
contract.resolve_function for 'batch_peer_2_peer'

[
      {
        "doc": "",
        "name": "p0",
        "type_tag": "Signer"
      },
      {
        "doc": "",
        "name": "p1",
        "type_tag": {
          "Vector": "Address"
        }
      },
      {
        "doc": "",
        "name": "p2",
        "type_tag": {
          "Vector": "U128"
        }
      }
    ]

and there is no such a function serializeAddress in src/lib/runtime/serde/serializer.ts

@wk3368 wk3368 closed this as completed May 12, 2022
@wk3368
Copy link
Collaborator

wk3368 commented May 12, 2022

Fixed in v2.1.1

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

No branches or pull requests

2 participants