diff --git a/serialization/Address/Address.go b/serialization/Address/Address.go index a1f6652..398a643 100644 --- a/serialization/Address/Address.go +++ b/serialization/Address/Address.go @@ -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 @@ -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)