@@ -100,7 +100,7 @@ func (decoder *TransactionDecoder) CreateSimpleTransaction(wrapper openwallet.Wa
100
100
}
101
101
102
102
if len (addresses ) == 0 {
103
- return fmt .Errorf ("[%s] have not addresses" , accountID )
103
+ return openwallet .Errorf (openwallet . ErrAccountNotAddress , "[%s] have not addresses" , accountID )
104
104
}
105
105
106
106
searchAddrs := make ([]string , 0 )
@@ -163,7 +163,7 @@ func (decoder *TransactionDecoder) CreateSimpleTransaction(wrapper openwallet.Wa
163
163
}
164
164
165
165
if findAddrBalance == nil {
166
- return fmt .Errorf ("the balance: %s is not enough" , amountStr )
166
+ return openwallet .Errorf (openwallet . ErrInsufficientBalanceOfAccount , "the balance: %s is not enough" , amountStr )
167
167
}
168
168
169
169
//最后创建交易单
@@ -231,6 +231,10 @@ func (decoder *TransactionDecoder) CreateTokenTransaction(wrapper openwallet.Wal
231
231
}
232
232
})
233
233
234
+ tokenBalanceNotEnough := false
235
+ balanceNotEnough := false
236
+ errStr := ""
237
+
234
238
amountDec , _ := decimal .NewFromString (amountStr )
235
239
236
240
for _ , addrBalance := range addrBalanceArray {
@@ -265,6 +269,7 @@ func (decoder *TransactionDecoder) CreateTokenTransaction(wrapper openwallet.Wal
265
269
266
270
//总消耗数量 = 转账数量 + 手续费
267
271
if addrBalance_dec .LessThan (amountDec .Add (feeInfo .Fee )) {
272
+ tokenBalanceNotEnough = true
268
273
continue
269
274
}
270
275
@@ -273,7 +278,10 @@ func (decoder *TransactionDecoder) CreateTokenTransaction(wrapper openwallet.Wal
273
278
//判断账户资源是否足够
274
279
isEnoughEnegry , energyRest , feeMini := decoder .wm .IsEnoughEnergyToTransferTRC20 (addrBalance .Balance .Address , trxBalance )
275
280
if ! isEnoughEnegry {
276
- return openwallet .Errorf (openwallet .ErrInsufficientFees , "address[%s] available energy: %d is less than feeMini: %d" , addrBalance .Balance .Address , energyRest , feeMini )
281
+ balanceNotEnough = true
282
+ errStr = fmt .Sprintf ("address[%s] available energy: %d is less than feeMini: %d" , addrBalance .Balance .Address , energyRest , feeMini )
283
+ continue
284
+
277
285
}
278
286
}
279
287
@@ -287,7 +295,12 @@ func (decoder *TransactionDecoder) CreateTokenTransaction(wrapper openwallet.Wal
287
295
}
288
296
289
297
if findAddrBalance == nil {
290
- return fmt .Errorf ("the balance: %s is not enough" , amountStr )
298
+ if tokenBalanceNotEnough {
299
+ return openwallet .Errorf (openwallet .ErrInsufficientTokenBalanceOfAddress ,"the balance: %s is not enough" , amountStr )
300
+ }
301
+ if balanceNotEnough {
302
+ return openwallet .Errorf (openwallet .ErrInsufficientFees , errStr )
303
+ }
291
304
}
292
305
293
306
//最后创建交易单
0 commit comments