public new async Task <AddressValidationResult> ValidateAsync( string address, bool skipChecksumValidation, bool skipWhiteAndBlacklistCheck) { if (!IconKeys.IsValidAddress(address)) { return(AddressValidationResult.AddressIsInvalid(AddressValidationError.FormatIsInvalid)); } var addressObj = new Address(address); if (addressObj.GetPrefix() == AddressPrefix.FromString(AddressPrefix.Contract)) { return(AddressValidationResult.AddressIsInvalid(AddressValidationError.FormatIsInvalid)); } if (skipWhiteAndBlacklistCheck) { address = address.ToLowerInvariant(); if (await _blockchainService.IsContractAsync(address) && !await _whitelistedAddressRepository.ContainsAsync(address) && await _blacklistedAddressRepository.ContainsAsync(address)) { return(AddressValidationResult.AddressIsInvalid(AddressValidationError.AddressIsBlacklisted)); } } return(AddressValidationResult.AddressIsValid()); }
/// <summary> /// Creates a wallet which uses the key pair /// </summary> public static KeyWallet Create() { var privateKey = IconKeys.CreatePrivateKey(); var publicKey = IconKeys.GetPublicKey(privateKey); return(new KeyWallet(privateKey, publicKey)); }
public void TestCreate() { var wallet = KeyWallet.Create(); Assert.True(IconKeys.IsValidAddress(wallet.GetAddress().ToString())); IWallet loadWallet = KeyWallet.Load(wallet.GetPrivateKey()); Assert.Equal(wallet.GetAddress(), loadWallet.GetAddress()); }
private void TestContractCreate() { var address = new Address(Contract); Assert.Equal(Contract, address.ToString()); Assert.Equal(AddressPrefix.Contract, address.GetPrefix().ToString()); Assert.True(IconKeys.IsValidAddress(address)); Assert.True(IconKeys.IsContractAddress(address)); }
public Address(AddressPrefix prefix, byte[] body) { if (!IconKeys.IsValidAddressBody(body)) { throw new ArgumentException("Invalid address"); } _prefix = prefix; _body = body; }
public void TestEoaAddress() { var address = new Address(Eoa); var prefix = address.GetPrefix().ToString(); Assert.Equal(Eoa, address.ToString()); Assert.Equal(AddressPrefix.Eoa, prefix); Assert.True(IconKeys.IsValidAddress(address)); Assert.False(IconKeys.IsContractAddress(address)); }
public Builder To(Address to) { if (!IconKeys.IsContractAddress(to)) { throw new ArgumentException("Only the contract address can be called."); } _to = to; return(this); }
public Address(string address) { var addressPrefix = IconKeys.GetAddressHexPrefix(address); if (addressPrefix == null) { throw new ArgumentException("Invalid address prefix"); } else if (!IconKeys.IsValidAddress(address)) { throw new ArgumentException("Invalid address"); } _prefix = addressPrefix; _body = GetAddressBody(address); }
/// <inheritdoc /> public Task <List <ScoreApi> > GetScoreApi(Address scoreAddress) { if (!IconKeys.IsContractAddress(scoreAddress)) { throw new ArgumentException("Only the contract address can be called."); } var requestId = GetCurrentUnixTime(); var requestParams = new RpcObject.Builder() .Put("address", new RpcValue(scoreAddress)) .Build(); var request = new Request(requestId, "icx_getScoreApi", requestParams); return(_provider.SendRequestAsync(request, FindConverter <List <ScoreApi> >())); }
/// <inheritdoc /> public Address GetAddress() { return(IconKeys.GetAddress(_publicKey)); }
/// <summary> /// Loads a key wallet from the private key /// </summary> public static KeyWallet Load(Bytes privateKey) { var publicKey = IconKeys.GetPublicKey(privateKey); return(new KeyWallet(privateKey, publicKey)); }
public static byte[] GetAddressBody(string address) { var cleanInput = IconKeys.CleanHexPrefix(address); return(Hex.Decode(cleanInput)); }