Add ability to set value for call & deploy txs
@@ -3,6 +3,7 @@ package client
import (
"encoding/hex"
"fmt"
+ "math/big"
"strings"
"time"
@@ -12,6 +13,7 @@ import (
"github.com/gogo/protobuf/proto"
"github.com/loomnetwork/go-loom"
"github.com/loomnetwork/go-loom/auth"
+ "github.com/loomnetwork/go-loom/common"
ptypes "github.com/loomnetwork/go-loom/plugin/types"
"github.com/loomnetwork/go-loom/types"
"github.com/loomnetwork/go-loom/vm"
@@ -469,11 +471,30 @@ func (c *DAppChainRPCClient) CommitDeployTx(
vmType vm.VMType,
code []byte,
name string,
+) ([]byte, error) {
+ return c.CommitDeployTxWithValue(
+ from,
+ signer,
+ vmType,
+ code,
+ name,
+ big.NewInt(0),
+ )
+}
+
+func (c *DAppChainRPCClient) CommitDeployTxWithValue(
+ from loom.Address,
+ signer auth.Signer,
+ vmType vm.VMType,
+ code []byte,
+ name string,
+ value *big.Int,
) ([]byte, error) {
deployTxBytes, err := proto.Marshal(&vm.DeployTx{
VmType: vmType,
Code: code,
Name: name,
+ Value: &types.BigUInt{Value: common.BigUInt{value}},
})
if err != nil {
return nil, err
@@ -515,6 +536,7 @@ func (c *DAppChainRPCClient) CommitMigrationTx(
Id: 3,
Data: msgBytes,
}
+
return c.CommitTx2(from, signer, tx)
}
@@ -524,10 +546,29 @@ func (c *DAppChainRPCClient) CommitCallTx(
signer auth.Signer,
vmType vm.VMType,
input []byte,
+) ([]byte, error) {
+ return c.CommitCallTxWithValue(
+ caller,
+ contract,
+ signer,
+ vmType,
+ input,
+ big.NewInt(0),
+ )
+}
+
+func (c *DAppChainRPCClient) CommitCallTxWithValue(
+ caller loom.Address,
+ contract loom.Address,
+ signer auth.Signer,
+ vmType vm.VMType,
+ input []byte,
+ value *big.Int,
) ([]byte, error) {
callTxBytes, err := proto.Marshal(&vm.CallTx{
VmType: vm.VMType(vmType),
Input: input,
+ Value: &types.BigUInt{Value: common.BigUInt{value}},
})
if err != nil {
return nil, err
@@ -546,5 +587,6 @@ func (c *DAppChainRPCClient) CommitCallTx(
Id: 2,
Data: msgBytes,
}
+
return c.CommitTx2(caller, signer, tx)
}
