Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generalize 'WalletAddressFromBytes' #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions serialization/Address/Address.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Address struct {
Hrp string
}

func WalletAddressFromBytes(payment []byte, staking []byte, network constants.Network) *Address {
func AddressFromBytes(payment []byte, paymentIsScript bool, staking []byte, stakingIsScript bool, network constants.Network) *Address {
var addr Address
addr.PaymentPart = payment
addr.StakingPart = staking
Expand All @@ -49,12 +49,30 @@ func WalletAddressFromBytes(payment []byte, staking []byte, network constants.Ne
} else {
addr.Network = TESTNET
}
if len(payment) == 0 {
if len(payment) == 0 && len(staking) == 0 {
return nil
} else if len(payment) == 0 {
if stakingIsScript {
addr.AddressType = NONE_SCRIPT
} else {
addr.AddressType = NONE_KEY
}
} else if len(staking) == 0 {
addr.AddressType = KEY_NONE
if paymentIsScript {
addr.AddressType = SCRIPT_NONE
} else {
addr.AddressType = KEY_NONE
}
} else {
addr.AddressType = KEY_KEY
if paymentIsScript && stakingIsScript {
addr.AddressType = SCRIPT_SCRIPT
} else if paymentIsScript && !stakingIsScript {
addr.AddressType = SCRIPT_KEY
} else if !paymentIsScript && stakingIsScript {
addr.AddressType = KEY_SCRIPT
} else {
addr.AddressType = KEY_KEY
}
}
addr.HeaderByte = (addr.AddressType << 4) | addr.Network
addr.Hrp = ComputeHrp(addr.AddressType, addr.Network)
Expand Down