Example #1
0
        public void Write(TxDeclaration declaration)
        {
            Write((byte)declaration.Type);
            switch (declaration.Type)
            {
            case DeclarationType.MultiSignature:
                Write((MultiSignature)declaration);
                break;

            case DeclarationType.HashLock:
                Write((HashLock)declaration);
                break;

            case DeclarationType.TimeLock:
                Write((TimeLock)declaration);
                break;

            case DeclarationType.Secret:
                Write((SecretRevelation)declaration);
                break;

            case DeclarationType.VendingMachine:
                Write((VendingMachine)declaration);
                break;

            default:
                throw new NotImplementedException();
            }
        }
Example #2
0
            public void Add(TransactionDeclarationEntity declarationEntity, TxDeclaration declaration)
            {
                switch (declaration.Type)
                {
                case DeclarationType.MultiSignature:
                    var multi = (MultiSignature)declaration;
                    MultiSignatures[multi] = declarationEntity;
                    break;

                case DeclarationType.HashLock:
                    var hashlock = (HashLock)declaration;
                    HashLocks[hashlock] = declarationEntity;
                    break;

                case DeclarationType.TimeLock:
                    var timelock = (TimeLock)declaration;
                    TimeLocks[timelock] = declarationEntity;
                    break;

                case DeclarationType.VendingMachine:
                    var machine = (VendingMachine)declaration;
                    VendingMachines[machine] = declarationEntity;
                    break;
                }
            }
        public void TryAdd(TransactionDeclarationEntity entity, TxDeclaration declaration)
        {
            // we can duplicate declarations like Secret Reveliation
            Declarations.Add(entity);

            // we include unly once Account declarations
            if (declaration is TxAddressDeclaration)
            {
                var address = ((TxAddressDeclaration)declaration).Address;
                if (!AddressDeclarations.ContainsKey(address))
                {
                    AddressDeclarations.Add(address, entity);
                }
            }
        }
 private void ApplyDeclaration(LedgerPostState state, TxDeclaration declaration)
 {
     if (declaration.Type == DeclarationType.MultiSignature)
     {
         var multisig = (MultiSignature)declaration;
         state.DeclareAccount(multisig);
     }
     else if (declaration.Type == DeclarationType.HashLock)
     {
         var hashLock = (HashLock)declaration;
         state.DeclareAccount(hashLock);
     }
     else if (declaration.Type == DeclarationType.TimeLock)
     {
         var timeLock = (TimeLock)declaration;
         state.DeclareAccount(timeLock);
     }
     else if (declaration.Type == DeclarationType.VendingMachine)
     {
         var machine = (VendingMachine)declaration;
         state.DeclareAccount(machine);
     }
 }
        public bool ImportDeclaration(string alias, TxDeclaration declaration)
        {
            AliasManager.SetAlias(alias, declaration);
            if (declarations.ContainsKey(alias))
            {
                return(false);
            }
            declarations.Add(alias, declaration);

            if (declaration is TxAddressDeclaration)
            {
                var address = ((TxAddressDeclaration)declaration).Address;
                AliasManager.SetAlias(address.Encoded, declaration);
                if (declarations.ContainsKey(address.Encoded))
                {
                    return(false);
                }
                declarations.Add(address.Encoded, declaration);

                AddressListener.Listen(address);
            }
            return(true);
        }
        public static Internals.TxDeclaration CreateDeclaration(TxDeclaration declaration)
        {
            switch (declaration.Type)
            {
            case DeclarationType.MultiSignature:
                return(CreateMultisignature((MultiSignature)declaration));

            case DeclarationType.HashLock:
                return(CreateHashLock((HashLock)declaration));

            case DeclarationType.Secret:
                return(CreateSecret((SecretRevelation)declaration));

            case DeclarationType.TimeLock:
                return(CreateTimeLock((TimeLock)declaration));

            case DeclarationType.VendingMachine:
                return(CreateVendingMachine((VendingMachine)declaration));

            default:
                throw new NotImplementedException();
            }
        }
Example #7
0
 public void AddDeclaration(TxDeclaration declaration)
 {
     Transaction.Declarations.Add(declaration);
 }
 // TODO not related to signatures
 public virtual void OnValidDeclaration(TxDeclaration key)
 {
 }
 private bool MatchInContext(TransactionDeclarationContext context, List <TransactionDeclarationEntity> declarations, TxDeclaration declaration, TransactionHash hash, int index)
 {
     foreach (var entity in declarations)
     {
         if (entity.TransactionHash.Equals(hash) && entity.Index == index)
         {
             context.TryAdd(entity, declaration);
             return(true);
         }
     }
     return(false);
 }
 public bool TryGetDeclaration(string label, out TxDeclaration declaration)
 {
     return(declarations.TryGetValue(label, out declaration));
 }
Example #11
0
        // we make sure that this transformer is called before other transformers of subtypes
        private long GetDeclarationId(TxDeclaration declaration, ProcessedDeclarations processed)
        {
            var  repositoryManager = DatabaseService.RepositoryManager;
            long?id = null;

            TransactionDeclarationEntity processedDeclaration;

            switch (declaration.Type)
            {
            case DeclarationType.MultiSignature:
                var multi = (MultiSignature)declaration;

                // case 1 transactions in this batch (ledger) has same declaration several times. We take id of the first occurence
                if (processed.MultiSignatures.TryGetValue(multi, out processedDeclaration))
                {
                    id = processedDeclaration.DeclarationId;
                    break;
                }

                // Case 2 the original declaration was submitted before this batch (ledger)
                id = repositoryManager.GetRepository <MultiSignatureAccountRepository>().GetByAddress(multi.Address)?.DeclarationId;
                break;

            case DeclarationType.HashLock:
                var hashlock = (HashLock)declaration;

                // case 1 transactions in this batch (ledger) has same declaration several times. We take id of the first occurence
                if (processed.HashLocks.TryGetValue(hashlock, out processedDeclaration))
                {
                    id = processedDeclaration.DeclarationId;
                    break;
                }

                // Case 2 the original declaration was submitted before this batch (ledger)
                id = repositoryManager.GetRepository <HashLockRepository>().GetByAddress(hashlock.Address)?.DeclarationId;
                break;

            case DeclarationType.TimeLock:
                var timelock = (TimeLock)declaration;

                // case 1 transactions in this batch (ledger) has same declaration several times. We take id of the first occurence
                if (processed.TimeLocks.TryGetValue(timelock, out processedDeclaration))
                {
                    id = processedDeclaration.DeclarationId;
                    break;
                }

                // Case 2 the original declaration was submitted before this batch (ledger)
                id = repositoryManager.GetRepository <TimeLockRepository>().GetByAddress(timelock.Address)?.DeclarationId;
                break;

            case DeclarationType.VendingMachine:
                var machine = (VendingMachine)declaration;

                // case 1 transactions in this batch (ledger) has same declaration several times. We take id of the first occurence
                if (processed.VendingMachines.TryGetValue(machine, out processedDeclaration))
                {
                    id = processedDeclaration.DeclarationId;
                    break;
                }

                // Case 2 the original declaration was submitted before this batch (ledger)
                id = repositoryManager.GetRepository <VendingMachineRepository>().GetByAddress(machine.Address)?.DeclarationId;
                break;
            }

            //

            // checked if this delaration already exist
            // get id from txdxEntity

            return(id ?? Repository.GetNextId());
        }