Skip to content

Commit 3d23d76

Browse files
Merge pull request #30 from everFinance/return-tx
fix(): fix sendTxData return tx
2 parents 6ae9b34 + 455189c commit 3d23d76

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func main() {
4141
#### Send Data
4242

4343
```golang
44-
id, err := wallet.SendData(
44+
tx, err := wallet.SendData(
4545
[]byte("123"), // Data bytes
4646
[]types.Tag{
4747
types.Tag{
@@ -60,7 +60,7 @@ Arweave occasionally experiences congestion, and a low Reward can cause a transa
6060

6161
```golang
6262
speedUp := int64(50) // means reward = reward * 150%
63-
id, err := wallet.SendDataSpeedUp(
63+
tx, err := wallet.SendDataSpeedUp(
6464
[]byte("123"), // Data bytes
6565
[]types.Tag{
6666
types.Tag{

wallet.go

+10-12
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ func (w *Wallet) SendWinstonSpeedUp(amount *big.Int, target string, tags []types
103103
return w.SendTransaction(tx)
104104
}
105105

106-
func (w *Wallet) SendData(data []byte, tags []types.Tag) (id string, err error) {
106+
func (w *Wallet) SendData(data []byte, tags []types.Tag) (tx types.Transaction, err error) {
107107
return w.SendDataSpeedUp(data, tags, 0)
108108
}
109109

110110
// SendDataSpeedUp set speedFactor for speed up
111111
// eg: speedFactor = 10, reward = 1.1 * reward
112-
func (w *Wallet) SendDataSpeedUp(data []byte, tags []types.Tag, speedFactor int64) (id string, err error) {
112+
func (w *Wallet) SendDataSpeedUp(data []byte, tags []types.Tag, speedFactor int64) (signedTx types.Transaction, err error) {
113113
reward, err := w.Client.GetTransactionPrice(data, nil)
114114
if err != nil {
115115
return
@@ -125,7 +125,9 @@ func (w *Wallet) SendDataSpeedUp(data []byte, tags []types.Tag, speedFactor int6
125125
Reward: fmt.Sprintf("%d", reward*(100+speedFactor)/100),
126126
}
127127

128-
return w.SendTransaction(tx)
128+
_, err = w.SendTransaction(tx)
129+
signedTx = *tx
130+
return
129131
}
130132

131133
// SendTransaction: if send success, should return pending
@@ -150,16 +152,16 @@ func (w *Wallet) SendTransaction(tx *types.Transaction) (id string, err error) {
150152
return
151153
}
152154

153-
func (w *Wallet) SendPst(contractId string, target string, qty *big.Int, customTags []types.Tag, speedFactor int64) (string, error) {
155+
func (w *Wallet) SendPst(contractId string, target string, qty *big.Int, customTags []types.Tag, speedFactor int64) (types.Transaction, error) {
154156
maxQty := big.NewInt(9007199254740991) // swc support max js integer
155157
if qty.Cmp(maxQty) > 0 {
156-
return "", fmt.Errorf("qty:%s can not more than max integer:%s", qty.String(), maxQty.String())
158+
return types.Transaction{}, fmt.Errorf("qty:%s can not more than max integer:%s", qty.String(), maxQty.String())
157159
}
158160

159161
// assemble tx tags
160162
swcTags, err := utils.PstTransferTags(contractId, target, qty.Int64())
161163
if err != nil {
162-
return "", err
164+
return types.Transaction{}, err
163165
}
164166

165167
if len(customTags) > 0 {
@@ -172,7 +174,7 @@ func (w *Wallet) SendPst(contractId string, target string, qty *big.Int, customT
172174
}
173175
for _, tag := range customTags {
174176
if _, ok := mmap[tag.Name]; ok {
175-
return "", errors.New("custom tags can not include smartweave tags")
177+
return types.Transaction{}, errors.New("custom tags can not include smartweave tags")
176178
}
177179
}
178180
swcTags = append(swcTags, customTags...)
@@ -181,9 +183,5 @@ func (w *Wallet) SendPst(contractId string, target string, qty *big.Int, customT
181183
// rand data
182184
data := strconv.Itoa(rand.Intn(9999))
183185
// send data tx
184-
txId, err := w.SendDataSpeedUp([]byte(data), swcTags, speedFactor)
185-
if err != nil {
186-
return "", err
187-
}
188-
return txId, nil
186+
return w.SendDataSpeedUp([]byte(data), swcTags, speedFactor)
189187
}

wallet_bundle.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ func (w *Wallet) SendBundleTxSpeedUp(bundleBinary []byte, tags []types.Tag, txSp
4040

4141
txTags := make([]types.Tag, 0)
4242
txTags = append(bundleTags, tags...)
43-
txId, err = w.SendDataSpeedUp(bundleBinary, txTags, txSpeed)
44-
return
43+
sentTx, err := w.SendDataSpeedUp(bundleBinary, txTags, txSpeed)
44+
if err != nil {
45+
return "", err
46+
}
47+
return sentTx.ID, err
4548
}
4649

4750
func (w *Wallet) SendBundleTx(bundleBinary []byte, tags []types.Tag) (txId string, err error) {

wallet_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ func Test_SendPstTransfer(t *testing.T) {
106106
//
107107
// contractId := "usjm4PCxUd5mtaon7zc97-dt-3qf67yPyqgzLnLqk5A"
108108
// target := "Ii5wAMlLNz13n26nYY45mcZErwZLjICmYd46GZvn4ck"
109-
// qty := int64(1)
110-
// arId, err := w.SendPstTransfer(contractId,target,qty,nil,50)
109+
// qty := big.NewInt(1)
110+
// arTx, err := w.SendPst(contractId,target,qty,nil,50)
111111
// assert.NoError(t, err)
112-
// t.Log(arId)
112+
// t.Log(arTx.ID)
113113
}

0 commit comments

Comments
 (0)