コード例 #1
0
        // NOTE no locks happen here because this callback is called from within a lock
        internal override Hash SettleSwap(Hash sourceHash, Address destination, IToken token, Numerics.BigInteger amount)
        {
            // check if tx was sent but not minded yet
            string tx = null;

            var inProgressMap = new StorageMap(TokenSwapper.InProgressTag, Swapper.Storage);

            if (inProgressMap.ContainsKey <Hash>(sourceHash))
            {
                tx = inProgressMap.Get <Hash, string>(sourceHash);

                if (!string.IsNullOrEmpty(tx))
                {
                    return(VerifyEthTx(sourceHash, tx));
                }
            }

            var total = Numerics.UnitConversion.ToDecimal(amount, token.Decimals);

            var ethKeys = EthereumKey.FromWIF(this.WIF);

            var destAddress = EthereumWallet.DecodeAddress(destination);

            try
            {
                Logger.Debug($"ETHSWAP: Trying transfer of {total} {token.Symbol} from {ethKeys.Address} to {destAddress}");
                var transferResult = ethAPI.TryTransferAsset(EthereumWallet.EthereumPlatform, token.Symbol, destAddress,
                                                             total, token.Decimals, out tx);

                if (transferResult == EthTransferResult.Success)
                {
                    // persist resulting tx hash as in progress
                    inProgressMap.Set <Hash, string>(sourceHash, tx);
                    Logger.Debug("broadcasted eth tx: " + tx);
                }
                else
                {
                    Logger.Error($"ETHSWAP: Transfer of {total} {token.Symbol} from {ethKeys.Address} to {destAddress} failed, no tx generated");
                }
            }
            catch (Exception e)
            {
                Logger.Error($"Exception during transfer: {e}");
                // we don't know if the transfer happend or not, therefore can't delete from inProgressMap yet.
                return(Hash.Null);
            }

            return(VerifyEthTx(sourceHash, tx));
        }
コード例 #2
0
        protected override string GetAvailableAddress(string wif)
        {
            var ethKeys = EthereumKey.FromWIF(wif);

            return(ethKeys.Address);
        }