Skip to content

Commit

Permalink
Merge pull request #224 from renproject/fix/bch-prefix
Browse files Browse the repository at this point in the history
Fix Bitcoin Cash gateway address validation
  • Loading branch information
tok-kkk authored Jan 13, 2022
2 parents e7fa5e6 + ae1f960 commit cb91701
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,22 @@ func (resolver *Resolver) validateGateway(gateway string, tx tx.Tx, input Partia
}
scriptAddressStr = scriptAddress.EncodeAddress()
case multichain.BitcoinCash:
scriptAddress, err := bitcoincash.NewAddressScriptHash(script, v0.NetParams(tx.Selector.Asset().OriginChain(), resolver.network))
params := v0.NetParams(tx.Selector.Asset().OriginChain(), resolver.network)

// Decode then re-encode the address to ensure any "bitcoincash:"
// prefixes are stripped.
addrEncodeDecoder := bitcoincash.NewAddressEncodeDecoder(params)
rawAddr, err := addrEncodeDecoder.DecodeAddress(multichain.Address(gateway))
if err != nil {
return fmt.Errorf("decoding bitcoin cash gateway=%v: %v", gateway, err)
}
gatewayAddr, err := addrEncodeDecoder.EncodeAddress(rawAddr)
if err != nil {
return fmt.Errorf("encoding bitcoin cash gateway=%v (raw=%v): %v", gateway, rawAddr, err)
}
gateway = string(gatewayAddr)

scriptAddress, err := bitcoincash.NewAddressScriptHash(script, params)
if err != nil {
return fmt.Errorf("unable to generate bitcoin cash address for UTXOGatewayScript: %v", err)
}
Expand Down

0 comments on commit cb91701

Please sign in to comment.