/// <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. /// </summary> /// <param name="addressString">address string.</param> public Address(string addressString) { using (var handle = new ErrorHandle()) { Initialize(handle, addressString, out CfdNetworkType outputNetwork, out CfdWitnessVersion outputWitnessVersion, out string outputLockingScript, out string outputHash); witnessVersion = outputWitnessVersion; hash = outputHash; network = outputNetwork; lockingScript = outputLockingScript; address = addressString; } }
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); }