/
contract.go
33 lines (27 loc) · 886 Bytes
/
contract.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package trx
import (
"github.com/lizc2003/gotron-sdk/pkg/client"
"github.com/lizc2003/gotron-sdk/pkg/contract"
"github.com/lizc2003/hdwallet/wallet"
)
func DeployContract(w *wallet.TrxWallet, client *client.GrpcClient, contractName string,
jsonAbi string, bytecode string,
feeLimit, consumeUserResourcePercent, originEnergyLimit int64) (string, error) {
abi, err := contract.JSONtoABI(jsonAbi)
if err != nil {
return "", err
}
txExt, err := client.DeployContract(w.DeriveAddress(), contractName, abi, bytecode,
feeLimit, consumeUserResourcePercent, originEnergyLimit)
if err != nil {
return "", err
}
return SignAndSendTx(w, client, txExt)
}
func GetContractAddress(client *client.GrpcClient, txId string) (string, error) {
info, err := client.GetTransactionInfoByID(txId)
if err != nil {
return "", err
}
return EncodeAddress(info.ContractAddress), nil
}