-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use address types for all operations
remove go-ethereum dependency
- Loading branch information
Showing
5 changed files
with
41 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,32 @@ | ||
package deposit_address | ||
|
||
import ( | ||
eth "github.com/ethereum/go-ethereum/common" | ||
"github.com/lombard-finance/chain/address" | ||
"github.com/lombard-finance/chain/chainid" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
const SuiAddressLength = 32 | ||
|
||
// CalcTweakBytes Compute the tweakBytes for a given request, dispatching on `blockchainType` | ||
func CalcTweakBytes( | ||
chainId chainid.LChainId, | ||
toAddress, lbtcAddress, auxData []byte, | ||
toAddress, lbtcAddress address.Address, | ||
auxData []byte, | ||
) ([]byte, error) { | ||
|
||
switch chainId.(type) { | ||
case chainid.EVMLChainId: | ||
if len(lbtcAddress) != eth.AddressLength { | ||
return nil, errors.Errorf("bad LbtcAddress (got %d bytes, expected %d)", len(lbtcAddress), eth.AddressLength) | ||
} | ||
if len(toAddress) != eth.AddressLength { | ||
return nil, errors.Errorf("bad ToAddress (got %d bytes, expected %d)", len(toAddress), eth.AddressLength) | ||
} | ||
return DepositTweak(lbtcAddress, toAddress, chainId, auxData) | ||
case chainid.SuiLChainId: | ||
if len(lbtcAddress) != SuiAddressLength { | ||
return nil, errors.Errorf("bad LbtcAddress (got %d bytes, expected %d)", len(lbtcAddress), SuiAddressLength) | ||
} | ||
if len(toAddress) != SuiAddressLength { | ||
return nil, errors.Errorf("bad ToAddress (got %d bytes, expected %d)", len(toAddress), SuiAddressLength) | ||
} | ||
return DepositTweak(lbtcAddress, toAddress, chainId, auxData) | ||
default: | ||
return nil, errors.Errorf("unsupported blockchain type: %s", chainId.Ecosystem().String()) | ||
if chainId.Ecosystem() != toAddress.Ecosystem() { | ||
return nil, errors.Errorf( | ||
"ecosystem mismatch between chain (%s) and to address (%s:%s)", | ||
chainId.Ecosystem().String(), | ||
toAddress.Ecosystem().String(), | ||
toAddress.String(), | ||
) | ||
} | ||
if chainId.Ecosystem() != lbtcAddress.Ecosystem() { | ||
return nil, errors.Errorf( | ||
"ecosystem mismatch between chain (%s) and LBTC address (%s:%s)", | ||
chainId.Ecosystem().String(), | ||
lbtcAddress.Ecosystem().String(), | ||
lbtcAddress.String(), | ||
) | ||
} | ||
return DepositTweak(lbtcAddress, toAddress, chainId, auxData) | ||
} |