예제 #1
0
    public static ChannelMigrationInfo decChannelMigrationInfo(byte[] raw)
    {
        ChannelMigrationInfo cmi = new ChannelMigrationInfo();
        int seek = 0;
        int len  = 0;

        len   = (int)raw.Range(seek, 2).AsBigInteger();
        seek += 2;
        BasicMethods.assert(len == 32, "channelId illegal");
        cmi.channelId = raw.Range(seek, len);
        seek         += len;

        len   = (int)raw.Range(seek, 2).AsBigInteger();
        seek += 2;
        BasicMethods.assert(BasicMethods._isLegalLength(len), "fromLedgerAddress illegal");
        cmi.fromLedgerAddress = raw.Range(seek, len);
        seek += len;

        len   = (int)raw.Range(seek, 2).AsBigInteger();
        seek += 2;
        BasicMethods.assert(BasicMethods._isLegalLength(len), "toLegerAddress illegal");
        cmi.toLegerAddress = raw.Range(seek, len);
        seek += len;

        len   = (int)raw.Range(seek, 2).AsBigInteger();
        seek += 2;
        cmi.migrationDeadline = raw.Range(seek, len).AsBigInteger();
        seek += len;

        BasicMethods.assert(raw.Length == seek, "decPaymentChannelInitializer raw data illegal");
        return(cmi);
    }
예제 #2
0
    public static SimplexPaymentChannel decSimplexPaymentChannel(byte[] raw)
    {
        SimplexPaymentChannel spc = new SimplexPaymentChannel();
        int seek = 0;
        int len  = 0;

        len   = (int)(raw.Range(seek, 2).AsBigInteger());
        seek += 2;
        BasicMethods.assert(len == 32, "channelId should be 32 bytes");
        spc.channelId = raw.Range(seek, len);
        seek         += len;

        len   = (int)raw.Range(seek, 2).AsBigInteger();
        seek += 2;
        BasicMethods.assert(BasicMethods._isLegalLength(len), "peerFrom illegal");
        spc.peerFrom = raw.Range(seek, len);
        seek        += len;

        len = (int)raw.Range(seek, 2).AsBigInteger();
        BasicMethods.assert(len >= 0, "seqNum illegal");
        seek      += 2;
        spc.seqNum = raw.Range(seek, len).AsBigInteger();
        seek      += len;

        len   = (int)raw.Range(seek, 2).AsBigInteger();
        seek += 2;
        spc.transferToPeer = decTokenTransfer(raw.Range(seek, len));
        seek += len;

        len   = (int)raw.Range(seek, 2).AsBigInteger();
        seek += 2;
        spc.pendingPayIds = decPayIdList(raw.Range(seek, len));
        seek += len;

        len = (int)raw.Range(seek, 2).AsBigInteger();
        BasicMethods.assert(len >= 0, "lastPayResolveDeadline illegal");
        seek += 2;
        spc.lastPayResolveDeadline = raw.Range(seek, len).AsBigInteger();
        seek += len;

        len = (int)raw.Range(seek, 2).AsBigInteger();
        BasicMethods.assert(len >= 0, "totalPendingAmount illegal");
        seek += 2;
        spc.totalPendingAmount = raw.Range(seek, len).AsBigInteger();
        seek += len;

        BasicMethods.assert(raw.Length == seek, "decSimplexPaymentChannel raw data illegal");
        return(spc);
    }
예제 #3
0
    public static Condition decCondition(byte[] raw)
    {
        Condition c    = new Condition();
        int       seek = 0;
        int       len  = 0;

        len   = (int)raw.Range(seek, 2).AsBigInteger();
        seek += 2;
        BasicMethods.assert(len == 1, "tokenType length illegal");
        c.conditionType = raw.Range(seek, 1)[0];
        BasicMethods.assert(c.conditionType <= getConditionType().VIRTUAL_CONTRACT, "conditionType illegal");
        seek += len;

        len   = (int)raw.Range(seek, 2).AsBigInteger();
        seek += 2;
        BasicMethods.assert(len == 32, "hashLock illegal");
        c.hashLock = raw.Range(seek, len);
        seek      += len;

        len   = (int)raw.Range(seek, 2).AsBigInteger();
        seek += 2;
        BasicMethods.assert(BasicMethods._isLegalLength(len), "deployedContractAddress illegal");
        c.deployedContractAddress = raw.Range(seek, len);
        seek += len;

        len   = (int)raw.Range(seek, 2).AsBigInteger();
        seek += 2;
        BasicMethods.assert(len == 32, "virtualContractAddress illegal");
        c.virtualContractAddress = raw.Range(seek, len);
        seek += len;

        len   = (int)raw.Range(seek, 2).AsBigInteger();
        seek += 2;
        c.argsQueryFinalization = raw.Range(seek, len);
        seek += len;

        len   = (int)raw.Range(seek, 2).AsBigInteger();
        seek += 2;
        c.argsQueryOutcome = raw.Range(seek, len);
        seek += len;

        BasicMethods.assert(raw.Length == seek, "decCondition raw data illegal");
        return(c);
    }
예제 #4
0
    public static AccountAmtPair decAccountAmtPair(byte[] raw)
    {
        AccountAmtPair aap  = new AccountAmtPair();
        int            seek = 0;
        int            len  = 0;

        len = (int)raw.Range(seek, 2).AsBigInteger();
        BasicMethods.assert(BasicMethods._isLegalLength(len), "account length error");
        seek       += 2;
        aap.account = raw.Range(seek, len);
        seek       += len;

        len     = (int)raw.Range(seek, 2).AsBigInteger();
        seek   += 2;
        aap.amt = raw.Range(seek, len).AsBigInteger();
        BasicMethods.assert(aap.amt >= 0, "amt error");
        seek += len;
        BasicMethods.assert(raw.Length == seek, "decAccountAmtPair raw data illegal");
        return(aap);
    }
예제 #5
0
    public static TokenInfo decTokenInfo(byte[] raw)
    {
        TokenInfo ti   = new TokenInfo();
        int       seek = 0;
        int       len  = 0;

        len   = (int)raw.Range(seek, 2).AsBigInteger();
        seek += 2;
        BasicMethods.assert(len == 1, "tokenType length illegal");
        ti.tokenType = raw.Range(seek, 1)[0];
        BasicMethods.assert(ti.tokenType <= getTokenType().GAS, "tokenType illegal");
        seek += len;

        len   = (int)raw.Range(seek, 2).AsBigInteger();
        seek += 2;
        BasicMethods.assert(BasicMethods._isLegalLength(len), "address illegal");
        ti.address = raw.Range(seek, len);
        seek      += len;
        BasicMethods.assert(raw.Length == seek, "decTokenInfo raw data illegal");
        return(ti);
    }
예제 #6
0
    public static ConditionalPay decConditionalPay(byte[] raw)
    {
        ConditionalPay cp   = new ConditionalPay();
        int            seek = 0;
        int            len  = 0;

        len             = (int)raw.Range(seek, 2).AsBigInteger();
        seek           += 2;
        cp.payTimestamp = raw.Range(seek, len).AsBigInteger();
        BasicMethods.assert(cp.payTimestamp > 0, "payTimestamp illegal");
        seek += len;

        len   = (int)raw.Range(seek, 2).AsBigInteger();
        seek += 2;
        BasicMethods.assert(BasicMethods._isLegalLength(len), "src illegal");
        cp.src = raw.Range(seek, len);
        seek  += len;

        len   = (int)raw.Range(seek, 2).AsBigInteger();
        seek += 2;
        BasicMethods.assert(BasicMethods._isLegalLength(len), "dest illegal");
        cp.dest = raw.Range(seek, len);
        seek   += len;

        len = (int)raw.Range(seek, 2).AsBigInteger();
        BasicMethods.assert(len >= 0, "conditions illegal");
        seek         += 2;
        cp.conditions = new Condition[len];

        for (int i = 0; i < len; i++)
        {
            int k = (int)raw.Range(seek, 2).AsBigInteger();
            seek            += 2;
            cp.conditions[i] = decCondition(raw.Range(seek, k));
            seek            += k;
        }

        len             = (int)raw.Range(seek, 2).AsBigInteger();
        seek           += 2;
        cp.transferFunc = decTransferFunction(raw.Range(seek, len));
        seek           += len;

        len   = (int)raw.Range(seek, 2).AsBigInteger();
        seek += 2;
        cp.resolveDeadline = raw.Range(seek, len).AsBigInteger();
        seek += len;

        len   = (int)raw.Range(seek, 2).AsBigInteger();
        seek += 2;
        cp.resolveTimeout = raw.Range(seek, len).AsBigInteger();
        seek += len;

        len   = (int)raw.Range(seek, 2).AsBigInteger();
        seek += 2;
        BasicMethods.assert(BasicMethods._isLegalLength(len), "payResolver illegal");
        cp.payResolver = raw.Range(seek, len);
        seek          += len;

        BasicMethods.assert(raw.Length == seek, "decConditionalPay raw data illegal");
        return(cp);
    }