Skip to content

Commit 8ded6cc

Browse files
committed
转账目标地址不存在时包含激活账户的消耗计算
1 parent 937ad4e commit 8ded6cc

8 files changed

+182
-85
lines changed

openwtester/manager_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func TestWalletManager_CreateAddress(t *testing.T) {
111111
tm := testInitWalletManager()
112112

113113
walletID := "WLHdqGtGGZkBHEyXmv1w82s2iZjWJjgWF8"
114-
accountID := "4pF3jRC2XokaaLZWiiLvxXrD8SKRYNuzcVCFkJdu6rkt"
114+
accountID := "C31rHUi8FJpwhWC2KTb5mMx9LUCSRpNnS1cG2QVMixYN"
115115
address, err := tm.CreateAddress(testApp, walletID, accountID, 1)
116116
if err != nil {
117117
log.Error(err)
@@ -129,6 +129,7 @@ func TestWalletManager_GetAddressList(t *testing.T) {
129129

130130
walletID := "WLHdqGtGGZkBHEyXmv1w82s2iZjWJjgWF8"
131131
accountID := "4pF3jRC2XokaaLZWiiLvxXrD8SKRYNuzcVCFkJdu6rkt"
132+
//accountID := "C31rHUi8FJpwhWC2KTb5mMx9LUCSRpNnS1cG2QVMixYN"
132133
list, err := tm.GetAddressList(testApp, walletID, accountID, 0, -1, false)
133134
if err != nil {
134135
log.Error("unexpected error:", err)

openwtester/transcation_assets_test.go

+35-26
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,11 @@ func TestTransfer_TRX(t *testing.T) {
123123
walletID := "WLHdqGtGGZkBHEyXmv1w82s2iZjWJjgWF8"
124124
accountID := "4pF3jRC2XokaaLZWiiLvxXrD8SKRYNuzcVCFkJdu6rkt"
125125
to := "TRJJ9Mq4aMjdmKWpTDJAgbYNoY2P9Facg5"
126+
//to := "TCa3csiJd8Xhx75GPWP9S3kyXX9PonMx7n"
126127

127128
testGetAssetsAccountBalance(tm, walletID, accountID)
128129

129-
rawTx, err := testCreateTransactionStep(tm, walletID, accountID, to, "0.03", "", nil)
130+
rawTx, err := testCreateTransactionStep(tm, walletID, accountID, to, "1.199920", "", nil)
130131
if err != nil {
131132
return
132133
}
@@ -155,7 +156,8 @@ func TestTransfer_TRC20(t *testing.T) {
155156
tm := testInitWalletManager()
156157
walletID := "WLHdqGtGGZkBHEyXmv1w82s2iZjWJjgWF8"
157158
accountID := "4pF3jRC2XokaaLZWiiLvxXrD8SKRYNuzcVCFkJdu6rkt"
158-
to := "TRJJ9Mq4aMjdmKWpTDJAgbYNoY2P9Facg5"
159+
//to := "TRJJ9Mq4aMjdmKWpTDJAgbYNoY2P9Facg5"
160+
to := "TCa3csiJd8Xhx75GPWP9S3kyXX9PonMx7n"
159161

160162
contract := openwallet.SmartContract{
161163
Address: "THvZvKPLHKLJhEFYKiyqj6j8G8nGgfg7ur",
@@ -194,10 +196,10 @@ func TestTransfer_TRC20(t *testing.T) {
194196
return
195197
}
196198

197-
_, err = testSubmitTransactionStep(tm, rawTx)
198-
if err != nil {
199-
return
200-
}
199+
//_, err = testSubmitTransactionStep(tm, rawTx)
200+
//if err != nil {
201+
// return
202+
//}
201203

202204
}
203205

@@ -206,7 +208,8 @@ func TestTransfer_TRC10(t *testing.T) {
206208
tm := testInitWalletManager()
207209
walletID := "WLHdqGtGGZkBHEyXmv1w82s2iZjWJjgWF8"
208210
accountID := "4pF3jRC2XokaaLZWiiLvxXrD8SKRYNuzcVCFkJdu6rkt"
209-
to := "TRJJ9Mq4aMjdmKWpTDJAgbYNoY2P9Facg5"
211+
//to := "TRJJ9Mq4aMjdmKWpTDJAgbYNoY2P9Facg5"
212+
to := "TCa3csiJd8Xhx75GPWP9S3kyXX9PonMx7n"
210213

211214
contract := openwallet.SmartContract{
212215
Address: "1002000",
@@ -236,19 +239,21 @@ func TestTransfer_TRC10(t *testing.T) {
236239
return
237240
}
238241

239-
_, err = testSubmitTransactionStep(tm, rawTx)
240-
if err != nil {
241-
return
242-
}
242+
//_, err = testSubmitTransactionStep(tm, rawTx)
243+
//if err != nil {
244+
// return
245+
//}
243246

244247
}
245248

246249

247250
func TestSummary(t *testing.T) {
248251
tm := testInitWalletManager()
249252
walletID := "WGVsUfTTVaCwAMRTqeJiDQsZ3vrWp9DzMA"
250-
accountID := "4pF3jRC2XokaaLZWiiLvxXrD8SKRYNuzcVCFkJdu6rkt"
253+
//accountID := "4pF3jRC2XokaaLZWiiLvxXrD8SKRYNuzcVCFkJdu6rkt"
254+
accountID := "C31rHUi8FJpwhWC2KTb5mMx9LUCSRpNnS1cG2QVMixYN"
251255
summaryAddress := "TRJJ9Mq4aMjdmKWpTDJAgbYNoY2P9Facg5"
256+
//summaryAddress := "TS11WZyPnT8qidwREcR8VDzNULCXxFeBMa"
252257

253258
testGetAssetsAccountBalance(tm, walletID, accountID)
254259

@@ -289,8 +294,10 @@ func TestSummary(t *testing.T) {
289294
func TestSummary_TRC10(t *testing.T) {
290295
tm := testInitWalletManager()
291296
walletID := "WGVsUfTTVaCwAMRTqeJiDQsZ3vrWp9DzMA"
292-
accountID := "4pF3jRC2XokaaLZWiiLvxXrD8SKRYNuzcVCFkJdu6rkt"
297+
//accountID := "4pF3jRC2XokaaLZWiiLvxXrD8SKRYNuzcVCFkJdu6rkt"
298+
accountID := "C31rHUi8FJpwhWC2KTb5mMx9LUCSRpNnS1cG2QVMixYN"
293299
summaryAddress := "TRJJ9Mq4aMjdmKWpTDJAgbYNoY2P9Facg5"
300+
//summaryAddress := "TS11WZyPnT8qidwREcR8VDzNULCXxFeBMa"
294301

295302
feesSupport := openwallet.FeesSupportAccount{
296303
AccountID: "5Tm3sqFap329wj3Du4DVXMkjAe85FVH3MaB6HSV8joj1",
@@ -349,33 +356,35 @@ func TestSummary_TRC10(t *testing.T) {
349356
func TestSummary_TRC20(t *testing.T) {
350357
tm := testInitWalletManager()
351358
walletID := "WGVsUfTTVaCwAMRTqeJiDQsZ3vrWp9DzMA"
352-
accountID := "4pF3jRC2XokaaLZWiiLvxXrD8SKRYNuzcVCFkJdu6rkt"
359+
//accountID := "4pF3jRC2XokaaLZWiiLvxXrD8SKRYNuzcVCFkJdu6rkt"
360+
accountID := "C31rHUi8FJpwhWC2KTb5mMx9LUCSRpNnS1cG2QVMixYN"
353361
summaryAddress := "TRJJ9Mq4aMjdmKWpTDJAgbYNoY2P9Facg5"
362+
//summaryAddress := "TS11WZyPnT8qidwREcR8VDzNULCXxFeBMa"
354363

355364
feesSupport := openwallet.FeesSupportAccount{
356365
AccountID: "5Tm3sqFap329wj3Du4DVXMkjAe85FVH3MaB6HSV8joj1",
357366
FixSupportAmount: "0.5",
358367
//FeesSupportScale: "1.3",
359368
}
360369

361-
//contract := openwallet.SmartContract{
362-
// Address: "THvZvKPLHKLJhEFYKiyqj6j8G8nGgfg7ur",
363-
// Symbol: "TRX",
364-
// Name: "TRONdice",
365-
// Token: "DICE",
366-
// Decimals: 6,
367-
// Protocol: "trc20",
368-
//}
369-
370370
contract := openwallet.SmartContract{
371-
Address: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
371+
Address: "THvZvKPLHKLJhEFYKiyqj6j8G8nGgfg7ur",
372372
Symbol: "TRX",
373-
Name: "Tether USD",
374-
Token: "USDT",
373+
Name: "TRONdice",
374+
Token: "DICE",
375375
Decimals: 6,
376376
Protocol: "trc20",
377377
}
378378

379+
//contract := openwallet.SmartContract{
380+
// Address: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
381+
// Symbol: "TRX",
382+
// Name: "Tether USD",
383+
// Token: "USDT",
384+
// Decimals: 6,
385+
// Protocol: "trc20",
386+
//}
387+
379388
testGetAssetsAccountBalance(tm, walletID, accountID)
380389

381390
testGetAssetsAccountTokenBalance(tm, walletID, accountID, contract)

tron/api.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (c *Client) Call(path string, param interface{}) (*gjson.Result, error) {
8585

8686
//getBalance 获取地址余额
8787
func (wm *WalletManager) getBalance(address string) (*openwallet.Balance, error) {
88-
account, err := wm.GetTRXAccount(address)
88+
account, _, err := wm.GetTRXAccount(address)
8989
if err != nil {
9090
return nil, err
9191
}

tron/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const (
4848
SUN int64 = 1 //最小单位
4949
TRX int64 = SUN * 1000000 //1 TRX = 1000000 * sun
5050
GasPrice = SUN * 10
51+
CreateAccountCost = SUN * 100000 //0.1 TRX = 100000 * sun
5152
)
5253

5354
//WalletConfig configs for Wallet

tron/contract.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func (wm *WalletManager) GetTRC20Balance(address string, contractAddress string)
197197
//GetTokenBalance 获取代币余额
198198
func (wm *WalletManager) GetTRC10Balance(address string, tokenID string) (int64, error) {
199199

200-
a, err := wm.GetTRXAccount(address)
200+
a, _, err := wm.GetTRXAccount(address)
201201
if err != nil {
202202
return 0, err
203203
}

tron/manager_account.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,21 @@ func (wm *WalletManager) GetAccount(address string) (account *openwallet.AssetsA
147147
// Parameters:
148148
// Account address,converted to a base64 string
149149
// Return value:
150-
func (wm *WalletManager) GetTRXAccount(address string) (account *Account, err error) {
150+
func (wm *WalletManager) GetTRXAccount(address string) (account *Account, exist bool, err error) {
151151
address = convertAddrToHex(address)
152152

153153
params := req.Param{"address": address}
154154
r, err := wm.WalletClient.Call("/wallet/getaccount", params)
155155
if err != nil {
156-
return nil, err
156+
return nil, false, err
157157
}
158158
account = NewAccount(r)
159159

160-
return account, nil
160+
if len(account.AddressHex) == 0 {
161+
return account, false, nil
162+
}
163+
164+
return account, true, nil
161165
}
162166

163167
// CreateAccount Done!

tron/manager_account_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func TestGetAccount(t *testing.T) {
4848

4949
var addr string
5050

51-
addr = "TFHtQPM6SJ2GTebArYkhvZKk4rc3WAmdgE"
51+
addr = "TF84rDKSaVXpFyzMvP8SPPzEChQ4QAP75N"
5252

5353
if r, err := tw.GetAccount(addr); err != nil {
5454
t.Errorf("GetAccount failed: %v\n", err)
@@ -87,9 +87,9 @@ func TestGetTRXAccount(t *testing.T) {
8787

8888
var addr string
8989

90-
addr = "TXphYHMUvT2ptHt8QtQb5i9T9DWUtfBWha"
90+
addr = "TNmR1WCd2VD6vqXkmDjkDUPF8nXQAFmzJF"
9191

92-
if r, err := tw.GetTRXAccount(addr); err != nil {
92+
if r, _, err := tw.GetTRXAccount(addr); err != nil {
9393
t.Errorf("GetAccount failed: %v\n", err)
9494
} else {
9595
t.Logf("GetAccount return: \n\t%+v\n", r)

0 commit comments

Comments
 (0)