Skip to content

Commit

Permalink
add abi parameter to go wrapper CreateAndSendTransaction (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
bxq2011hust authored Jan 5, 2024
1 parent 821adbe commit 14b9b42
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ deps
*.dll

# Fortran module files
*.mod
*.smod
*.sum

# Compiled Static libraries
*.lai
Expand Down
16 changes: 9 additions & 7 deletions bindings/go/csdk/csdk_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,32 +536,34 @@ func (csdk *CSDK) RegisterBlockNotifier(chanData *CallbackChan) { // TODO: imple
C.bcos_sdk_register_block_notifier(csdk.sdk, csdk.groupID, setContext(chanData), C.bcos_sdk_c_struct_response_cb(C.on_recv_notify_resp_callback))
}

func (csdk *CSDK) CreateAndSendTransaction(chanData *CallbackChan, to string, data, extraData string, withProof bool) ([]byte, error) {
func (csdk *CSDK) CreateAndSendTransaction(chanData *CallbackChan, to string, data, abi, extraData string, withProof bool) ([]byte, error) {
cTo := C.CString(to)
defer C.free(unsafe.Pointer(cTo))
cProof := C.int(0)
if withProof {
cProof = C.int(1)
}
cData := C.CString(data)
defer C.free(unsafe.Pointer(cData))
cAbi := C.CString(abi)
defer C.free(unsafe.Pointer(cAbi))
cExtraData := C.CString(extraData)
defer C.free(unsafe.Pointer(cExtraData))
var tx_hash *C.char
var signed_tx *C.char
defer C.free(unsafe.Pointer(cTo))
defer C.free(unsafe.Pointer(cData))
defer C.free(unsafe.Pointer(cExtraData))
defer C.bcos_sdk_c_free(unsafe.Pointer(tx_hash))
defer C.bcos_sdk_c_free(unsafe.Pointer(signed_tx))
block_limit := C.bcos_rpc_get_block_limit(csdk.sdk, csdk.groupID)
if block_limit < 0 {
return nil, fmt.Errorf("group not exist, group: %s", C.GoString(csdk.groupID))
}
csdk.keyPairMutex.Lock()
C.bcos_sdk_create_signed_transaction_ver_extra_data(csdk.keyPair, csdk.groupID, csdk.chainID, cTo, cData, nil, block_limit, 0, cExtraData, &tx_hash, &signed_tx)
C.bcos_sdk_create_signed_transaction_ver_extra_data(csdk.keyPair, csdk.groupID, csdk.chainID, cTo, cData, cAbi, block_limit, 0, cExtraData, &tx_hash, &signed_tx)
if C.bcos_sdk_is_last_opr_success() == 0 {
csdk.keyPairMutex.Unlock()
return nil, fmt.Errorf("bcos_sdk_create_signed_transaction, error: %s", C.GoString(C.bcos_sdk_get_last_error_msg()))
}
csdk.keyPairMutex.Unlock()
defer C.bcos_sdk_c_free(unsafe.Pointer(tx_hash))
defer C.bcos_sdk_c_free(unsafe.Pointer(signed_tx))
txHash, err := hex.DecodeString(strings.TrimPrefix(C.GoString(tx_hash), "0x"))
if err != nil {
return nil, err
Expand Down

0 comments on commit 14b9b42

Please sign in to comment.