Skip to content

Commit ca30e40

Browse files
authored
Merge pull request #134 from renproject/fix/validation
Minor validation fixes
2 parents 18bf56d + 0615fe5 commit ca30e40

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

chain/bitcoin/address.go

+7
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ func NewAddressDecoder(params *chaincfg.Params) AddressDecoder {
9191

9292
// DecodeAddress implements the address.Decoder interface
9393
func (decoder AddressDecoder) DecodeAddress(addr address.Address) (address.RawAddress, error) {
94+
// The btcutil package assumes the address being decoded only contains
95+
// valid ASCII characters between 0-255.
96+
for _, c := range addr {
97+
if c > 255 {
98+
return nil, fmt.Errorf("invalid address: bad character %v", c)
99+
}
100+
}
94101
decodedAddr, err := btcutil.DecodeAddress(string(addr), decoder.params)
95102
if err != nil {
96103
return nil, fmt.Errorf("decode address: %v", err)

chain/bitcoin/address_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -1 +1,22 @@
11
package bitcoin_test
2+
3+
import (
4+
"github.com/btcsuite/btcd/chaincfg"
5+
"github.com/renproject/multichain/api/address"
6+
"github.com/renproject/multichain/chain/bitcoin"
7+
8+
. "github.com/onsi/ginkgo"
9+
. "github.com/onsi/gomega"
10+
)
11+
12+
var _ = Describe("Bitcoin", func() {
13+
Context("when decoding address with invalid characters", func() {
14+
It("should not panic", func() {
15+
decoder := bitcoin.NewAddressDecoder(&chaincfg.MainNetParams)
16+
Expect(func() {
17+
_, err := decoder.DecodeAddress(address.Address(rune(256)))
18+
Expect(err).To(HaveOccurred())
19+
}).ToNot(Panic())
20+
})
21+
})
22+
})

chain/evm/client.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -67,25 +67,26 @@ func (client *Client) Tx(ctx context.Context, txID pack.Bytes) (account.Tx, pack
6767
Signer: types.NewEIP155Signer(chainID),
6868
}
6969
if pending {
70-
return &pendingTx, 0, nil
70+
// Transaction has not been included in a block yet.
71+
return nil, 0, fmt.Errorf("tx %v is pending", txID)
7172
}
7273

7374
receipt, err := client.EthClient.TransactionReceipt(ctx, common.BytesToHash(txID))
7475
if err != nil {
7576
return nil, pack.NewU64(0), fmt.Errorf("fetching recipt for tx %v : %v", txID, err)
7677
}
7778

78-
// if no receipt, tx has 0 confirmations
7979
if receipt == nil {
80+
// Transaction has 0 confirmations.
8081
return &pendingTx, 0, nil
8182
}
8283

83-
// reverted tx
8484
if receipt.Status == 0 {
85+
// Transaction has been reverted.
8586
return nil, pack.NewU64(0), fmt.Errorf("tx %v reverted, reciept status 0", txID)
8687
}
8788

88-
// tx confirmed
89+
// Transaction has been confirmed.
8990
confirmedTx := Tx{
9091
tx,
9192
types.LatestSignerForChainID(chainID),

0 commit comments

Comments
 (0)