/// <summary> /// constructor for redeem script. /// </summary> /// <param name="script">redeem script</param> /// <param name="type">address type</param> /// <param name="networkType">network type</param> public Address(Script script, CfdAddressType type, CfdNetworkType networkType) { if (script is null) { throw new ArgumentNullException(nameof(script)); } using (var handle = new ErrorHandle()) { var ret = NativeMethods.CfdCreateAddress( handle.GetHandle(), (int)type, "", script.ToHexString(), (int)networkType, out IntPtr outputAddress, out IntPtr outputLockingScript, out IntPtr outputP2shSegwitLockingScript); if (ret != CfdErrorCode.Success) { handle.ThrowError(ret); } address = CCommon.ConvertToString(outputAddress); lockingScript = CCommon.ConvertToString(outputLockingScript); p2shSegwitLockingScript = CCommon.ConvertToString(outputP2shSegwitLockingScript); Initialize(handle, address, out _, out CfdWitnessVersion outputWitnessVersion, out _, out string outputHash); witnessVersion = outputWitnessVersion; hash = outputHash; network = networkType; addressType = type; } }
/// <summary> /// constructor for schnorr pubkey. /// </summary> /// <param name="pubkey">schnorr public key</param> /// <param name="type">address type</param> /// <param name="network">network type</param> public Address(SchnorrPubkey pubkey, CfdAddressType type, CfdNetworkType network) { if (pubkey is null) { throw new ArgumentNullException(nameof(pubkey)); } using (var handle = new ErrorHandle()) { var ret = NativeMethods.CfdCreateAddress( handle.GetHandle(), (int)type, pubkey.ToHexString(), "", (int)network, out IntPtr outputAddress, out IntPtr outputLockingScript, out IntPtr outputP2shSegwitLockingScript); if (ret != CfdErrorCode.Success) { handle.ThrowError(ret); } address = CCommon.ConvertToString(outputAddress); lockingScript = CCommon.ConvertToString(outputLockingScript); p2shSegwitLockingScript = CCommon.ConvertToString(outputP2shSegwitLockingScript); Initialize(handle, address, out network, out witnessVersion, out string tempLockingScript, out hash); this.network = network; addressType = type; } }
/// <summary> /// get multisig address list. /// </summary> /// <param name="multisigScript">multisig script</param> /// <param name="networkType">network type</param> /// <param name="addressType">address type</param> /// <returns>address list</returns> public static Address[] GetMultisigAddresses(Script multisigScript, CfdNetworkType networkType, CfdAddressType addressType ) { if (multisigScript is null) { throw new ArgumentNullException(nameof(multisigScript)); } using (var handle = new ErrorHandle()) { var ret = NativeMethods.CfdGetAddressesFromMultisig( handle.GetHandle(), multisigScript.ToHexString(), (int)networkType, (int)addressType, out IntPtr multisigHandle, out uint maxKeyNum); if (ret != CfdErrorCode.Success) { handle.ThrowError(ret); } try { Address[] addrList = new Address[maxKeyNum]; for (uint index = 0; index < maxKeyNum; ++index) { IntPtr address = IntPtr.Zero; IntPtr pubkey = IntPtr.Zero; ret = NativeMethods.CfdGetAddressFromMultisigKey( handle.GetHandle(), multisigHandle, index, out address, out pubkey); if (ret != CfdErrorCode.Success) { handle.ThrowError(ret); } CCommon.ConvertToString(pubkey); string addr = CCommon.ConvertToString(address); addrList[index] = new Address(addr); } return(addrList); } finally { NativeMethods.CfdFreeAddressesMultisigHandle( handle.GetHandle(), multisigHandle); } } }
private void Initialize(ErrorHandle handle, string addressString, out CfdNetworkType outputNetwork, out CfdWitnessVersion outputWitnessVersion, out string outputLockingScript, out string outputHash) { var ret = NativeMethods.CfdGetAddressInfo( handle.GetHandle(), addressString, out int networkType, out int hashType, out int segwitVersion, out IntPtr lockingScript, out IntPtr hashString); if (ret != CfdErrorCode.Success) { handle.ThrowError(ret); } outputNetwork = (CfdNetworkType)networkType; addressType = (CfdAddressType)hashType; outputWitnessVersion = (CfdWitnessVersion)segwitVersion; outputLockingScript = CCommon.ConvertToString(lockingScript); outputHash = CCommon.ConvertToString(hashString); }
/// <summary> /// set address type for p2sh-segwit. /// </summary> /// <param name="addrType">address type</param> public void SetAddressType(CfdAddressType addrType) { addressType = addrType; }