public static BigInteger getCooperativeWithdrawSeqNum(byte[] _channelId) { BasicMethods.assert(BasicMethods._isByte32(_channelId), "_channelId illegal"); LedgerStruct.Channel c = LedgerStruct.getChannelMap(_channelId); return(LedgerChannel.getCooperativeWithdrawSeqNumInner(c)); }
public static BigInteger getTotalBalance(byte[] _channelId) { BasicMethods.assert(BasicMethods._isByte32(_channelId), "_channelId illegal"); LedgerStruct.Channel c = LedgerStruct.getChannelMap(_channelId); return(LedgerChannel.getTotalBalanceInner(c)); }
public static BigInteger getSettleFinalizedTime(byte[] _channelId) { BasicMethods.assert(BasicMethods._isByte32(_channelId), "_channelId illegal"); LedgerStruct.Channel c = LedgerStruct.getChannelMap(_channelId); return(LedgerChannel.getSettleFinalizedTimeInner(c)); }
public static byte getChannelStatus(byte[] _channelId) { BasicMethods.assert(BasicMethods._isByte32(_channelId), "_channelId illegal"); LedgerStruct.Channel c = LedgerStruct.getChannelMap(_channelId); return(LedgerChannel.getChannelStatusInner(c)); }
public static BigInteger getBalanceLimitInner(byte[] tokenAddr) { BasicMethods.assert(BasicMethods._isLegalAddress(tokenAddr), "Token address is illegal"); return(Storage.Get(Storage.CurrentContext, BalanceLimitsPrefix.Concat(tokenAddr)).ToBigInteger()); }
public static Object Main(string operation, params object[] args) { if (Runtime.Trigger == TriggerType.Verification) { return(true); } else if (Runtime.Trigger == TriggerType.Application) { if (operation == "init") { BasicMethods.assert(args.Length == 2, "init parameter error"); byte[] _payRegistryHash = (byte[])args[0]; byte[] _celerWalletHash = (byte[])args[1]; return(init(_payRegistryHash, _celerWalletHash)); } if (operation == "setBalanceLimits") { BasicMethods.assert(args.Length == 2, "setBalanceLimits parameter error"); byte[][] _tokenAddrs = (byte[][])args[0]; BigInteger[] _celerWalletHash = (BigInteger[])args[1]; return(setBalanceLimits(_tokenAddrs, _celerWalletHash)); } if (operation == "disableBalanceLimits") { BasicMethods.assert(args.Length == 0, "disableBalanceLimits parameter error"); return(disableBalanceLimits()); } if (operation == "enableBalanceLimits") { BasicMethods.assert(args.Length == 0, "enableBalanceLimits parameter error"); return(enableBalanceLimits()); } if (operation == "openChannel") { BasicMethods.assert(args.Length == 2, "openChannel parameter error"); byte[] _openRequest = (byte[])args[0]; byte[][] pubKeys = (byte[][])args[1]; return(openChannel(_openRequest, pubKeys)); } if (operation == "deposit") { BasicMethods.assert(args.Length == 4, "deposit parameter error"); byte[] _sender = (byte[])args[0]; byte[] _channelId = (byte[])args[1]; byte[] _receiver = (byte[])args[2]; BigInteger _transferFromAmount = (BigInteger)args[3]; return(deposit(_sender, _channelId, _receiver, _transferFromAmount)); } if (operation == "depositInBatch") { BasicMethods.assert(args.Length == 4, "depositInBatch parameter error"); byte[][] _sender = (byte[][])args[0]; byte[][] _channelIds = (byte[][])args[1]; byte[][] _receivers = (byte[][])args[2]; BigInteger[] _transferFromAmounts = (BigInteger[])args[3]; return(depositInBatch(_sender, _channelIds, _receivers, _transferFromAmounts)); } if (operation == "snapshotStates") { BasicMethods.assert(args.Length == 2, "snapshotStates parameter error"); byte[] _signedSimplexStateArray = (byte[])args[0]; byte[][] pubKeys = (byte[][])args[1]; return(snapshotStates(_signedSimplexStateArray, pubKeys)); } if (operation == "intendWithdraw") { BasicMethods.assert(args.Length == 4, "intendWithdraw parameter error"); byte[] _channelId = (byte[])args[0]; BigInteger _amount = (BigInteger)args[1]; byte[] _recipientChannelId = (byte[])args[2]; byte[] _sender = (byte[])args[3]; return(intendWithdraw(_channelId, _amount, _recipientChannelId, _sender)); } if (operation == "confirmWithdraw") { BasicMethods.assert(args.Length == 1, "confirmWithdraw parameter error"); byte[] _channelId = (byte[])args[0]; return(confirmWithdraw(_channelId)); } if (operation == "vetoWithdraw") { BasicMethods.assert(args.Length == 2, "vetoWithdraw parameter error"); byte[] _channelId = (byte[])args[0]; byte[] _sender = (byte[])args[1]; return(vetoWithdraw(_channelId, _sender)); } if (operation == "cooperativeWithdraw") { BasicMethods.assert(args.Length == 2, "cooperativeWithdraw parameter error"); byte[] _cooperativeWithdrawRequest = (byte[])args[0]; byte[][] pubKeys = (byte[][])args[1]; return(cooperativeWithdraw(_cooperativeWithdrawRequest, pubKeys)); } if (operation == "intendSettle") { BasicMethods.assert(args.Length == 3, "intendSettle parameter error"); byte[] _signedSimplexStateArray = (byte[])args[0]; byte[] _sender = (byte[])args[1]; byte[][] pubKeys = (byte[][])args[2]; return(intendSettle(_signedSimplexStateArray, _sender, pubKeys)); } if (operation == "clearPays") { BasicMethods.assert(args.Length == 3, "clearPays parameter error"); byte[] _channelId = (byte[])args[0]; byte[] _peerFrom = (byte[])args[1]; byte[] _payIdList = (byte[])args[2]; return(clearPays(_channelId, _peerFrom, _payIdList)); } if (operation == "confirmSettle") { BasicMethods.assert(args.Length == 1, "confirmSettle parameter error"); byte[] _channelId = (byte[])args[0]; return(confirmSettle(_channelId)); } if (operation == "cooperativeSettle") { BasicMethods.assert(args.Length == 2, "cooperativeSettle parameter error"); byte[] _settleRequest = (byte[])args[0]; byte[][] pubKeys = (byte[][])args[1]; return(cooperativeSettle(_settleRequest, pubKeys)); } if (operation == "migrateChannelTo") { BasicMethods.assert(args.Length == 2, "migrateChannelTo parameter error"); byte[] _migrationRequest = (byte[])args[0]; byte[][] pubKeys = (byte[][])args[1]; byte[] sender = ExecutionEngine.CallingScriptHash; return(migrateChannelTo(_migrationRequest, sender, pubKeys)); } if (operation == "migrateChannelFrom") { BasicMethods.assert(args.Length == 3, "migrateChannelFrom parameter error"); byte[] _fromLedgerAddr = (byte[])args[0]; byte[] _migrationRequest = (byte[])args[1]; byte[][] pubKeys = (byte[][])args[2]; return(migrateChannelFrom(_fromLedgerAddr, _migrationRequest, pubKeys)); } if (operation == "getSettleFinalizedTime") { BasicMethods.assert(args.Length == 1, "getSettleFinalizedTime parameter error"); byte[] _channelId = (byte[])args[0]; return(getSettleFinalizedTime(_channelId)); } if (operation == "getTokenContract") { BasicMethods.assert(args.Length == 1, "getTokenContract parameter error"); byte[] _channelId = (byte[])args[0]; return(getTokenContract(_channelId)); } if (operation == "getTokenType") { BasicMethods.assert(args.Length == 1, "getTokenType parameter error"); byte[] _channelId = (byte[])args[0]; return(getTokenType(_channelId)); } if (operation == "getChannelStatus") { BasicMethods.assert(args.Length == 1, "getChannelStatus parameter error"); byte[] _channelId = (byte[])args[0]; return(getChannelStatus(_channelId)); } if (operation == "getCooperativeWithdrawSeqNum") { BasicMethods.assert(args.Length == 1, "getCooperativeWithdrawSeqNum parameter error"); byte[] _channelId = (byte[])args[0]; return(getCooperativeWithdrawSeqNum(_channelId)); } if (operation == "getTotalBalance") { BasicMethods.assert(args.Length == 1, "getTotalBalance parameter error"); byte[] _channelId = (byte[])args[0]; return(getTotalBalance(_channelId)); } if (operation == "getBalanceMap") { BasicMethods.assert(args.Length == 1, "getBalanceMap parameter error"); byte[] _channelId = (byte[])args[0]; return(getBalanceMap(_channelId)); } if (operation == "getChannelMigrationArgs") { BasicMethods.assert(args.Length == 1, "getChannelMigrationArgs parameter error"); byte[] _channelId = (byte[])args[0]; return(getChannelMigrationArgs(_channelId)); } if (operation == "getPeersMigrationInfo") { BasicMethods.assert(args.Length == 1, "getPeersMigrationInfo parameter error"); byte[] _channelId = (byte[])args[0]; return(getPeersMigrationInfo(_channelId)); } if (operation == "getDisputeTimeout") { BasicMethods.assert(args.Length == 1, "getDisputeTimeout parameter error"); byte[] _channelId = (byte[])args[0]; return(getDisputeTimeout(_channelId)); } if (operation == "getMigratedTo") { BasicMethods.assert(args.Length == 1, "getMigratedTo parameter error"); byte[] _channelId = (byte[])args[0]; return(getMigratedTo(_channelId)); } if (operation == "getStateSeqNumMap") { BasicMethods.assert(args.Length == 1, "getStateSeqNumMap parameter error"); byte[] _channelId = (byte[])args[0]; return(getStateSeqNumMap(_channelId)); } if (operation == "getTransferOutMap") { BasicMethods.assert(args.Length == 1, "getTransferOutMap parameter error"); byte[] _channelId = (byte[])args[0]; return(getTransferOutMap(_channelId)); } if (operation == "getNextPayIdListHashMap") { BasicMethods.assert(args.Length == 1, "getNextPayIdListHashMap parameter error"); byte[] _channelId = (byte[])args[0]; return(getNextPayIdListHashMap(_channelId)); } if (operation == "getLastPayResolveDeadlineMap") { BasicMethods.assert(args.Length == 1, "getLastPayResolveDeadlineMap parameter error"); byte[] _channelId = (byte[])args[0]; return(getLastPayResolveDeadlineMap(_channelId)); } if (operation == "getPendingPayOutMap") { BasicMethods.assert(args.Length == 1, "getPendingPayOutMap parameter error"); byte[] _channelId = (byte[])args[0]; return(getPendingPayOutMap(_channelId)); } if (operation == "getWithdrawIntent") { BasicMethods.assert(args.Length == 1, "getWithdrawIntent parameter error"); byte[] _channelId = (byte[])args[0]; return(getWithdrawIntent(_channelId)); } if (operation == "getChannelStatusNum") { BasicMethods.assert(args.Length == 1, "getChannelStatusNum parameter error"); BigInteger _channelStatus = (BigInteger)args[0]; return(getChannelStatusNum(_channelStatus)); } if (operation == "getPayRegistry") { BasicMethods.assert(args.Length == 0, "getPayRegistry parameter error"); return(getPayRegistry()); } if (operation == "getCelerWallet") { BasicMethods.assert(args.Length == 0, "getCelerWallet parameter error"); return(getCelerWallet()); } if (operation == "getBalanceLimit") { BasicMethods.assert(args.Length == 1, "getBalanceLimit parameter error"); byte[] _tokenAddr = (byte[])args[0]; return(getBalanceLimit(_tokenAddr)); } if (operation == "getBalanceLimitsEnabled") { BasicMethods.assert(args.Length == 0, "getBalanceLimitsEnabled parameter error"); return(getBalanceLimitsEnabled()); } } return(false); }
private static BigInteger _calculateNumericLogicPayment(PbEntity.ConditionalPay _pay, byte[][] _preimages, byte _funcType) { int j = 0; BigInteger amount = 0; bool hasContracCond = false; PbEntity.ConditionType ConditionType = PbEntity.getConditionType(); PbEntity.TransferFunctionType TransferFunctionType = PbEntity.getTransferFunctionType(); PbEntity.Condition[] conditions = _pay.conditions; for (var i = 0; i < conditions.Length; i++) { PbEntity.Condition cond = _pay.conditions[i]; if (cond.conditionType == ConditionType.HASH_LOCK) { BasicMethods.assert(SmartContract.Sha256(_preimages[j]) == cond.hashLock, "wrong preimage"); j++; } else if ( cond.conditionType == ConditionType.DEPLOYED_CONTRACT || cond.conditionType == ConditionType.VIRTUAL_CONTRACT ) { byte[] numericCondHash = _getCondAddress(cond); BasicMethods.DynamicCallContract dyncall = (BasicMethods.DynamicCallContract)numericCondHash.ToDelegate(); BasicMethods.assert((bool)dyncall("isFinalized", new object[] { cond.argsQueryFinalization }), "Condition is not finalized"); BigInteger outcome = (BigInteger)dyncall("getOutcome", new object[] { cond.argsQueryOutcome }); if (_funcType == TransferFunctionType.NUMERIC_ADD) { amount = amount + outcome; } else if (_funcType == TransferFunctionType.NUMERIC_MAX) { amount = max(amount, outcome); } else if (_funcType == TransferFunctionType.NUMERIC_MIN) { if (hasContracCond) { amount = min(amount, outcome); } else { amount = outcome; } } else { BasicMethods.assert(false, "error"); } hasContracCond = true; } else { BasicMethods.assert(false, "condition type error"); } } PbEntity.TransferFunction transferFunction = _pay.transferFunc; PbEntity.TokenTransfer tokenTransfer = transferFunction.maxTransfer; PbEntity.AccountAmtPair accountAmtPair = tokenTransfer.receiver; if (hasContracCond) { BasicMethods.assert(amount <= accountAmtPair.amt, "exceed max transfer amount"); return(amount); } else { return(accountAmtPair.amt); } }
public static byte[] getPayRegistryHash() { byte[] payRegistryHash = Storage.Get(Storage.CurrentContext, PayRegistryHashKey); BasicMethods.assert(BasicMethods._isLegalAddress(payRegistryHash), "empty pay registry contract hash"); return(payRegistryHash); }
public static byte[] resolve(byte[] virtHashId) { byte[] storedVirtAddr = Storage.Get(Storage.CurrentContext, Virt2RealPrefix.Concat(virtHashId)); BasicMethods.assert(BasicMethods._isLegalAddress(storedVirtAddr), "nonexistent virtual address"); return(storedVirtAddr); }
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); }
public static void _whenPaused() { BasicMethods.assert(getPausedStatus(), "Pausable: paused"); }
public static object Main(string method, object[] args) { if (Runtime.Trigger == TriggerType.Verification)//取钱才会涉及这里 { return(false); } else if (Runtime.Trigger == TriggerType.VerificationR) { return(false); } else if (Runtime.Trigger == TriggerType.Application) { if (method == "unpause") { BasicMethods.assert(args.Length == 1, "params length error"); byte[] invoker = (byte[])args[0]; return(unpause(invoker)); } if (method == "addPauser") { BasicMethods.assert(args.Length == 2, "params length error"); byte[] invoker = (byte[])args[0]; byte[] account = (byte[])args[1]; return(addPauser(invoker, account)); } if (method == "removePauser") { BasicMethods.assert(args.Length == 2, "params length error"); byte[] invoker = (byte[])args[0]; byte[] account = (byte[])args[1]; return(removePauser(invoker, account)); } if (method == "create") { BasicMethods.assert(args.Length == 4, "params length error"); byte[] invoker = (byte[])args[0]; byte[][] owners = (byte[][])args[1]; byte[] theOperator = (byte[])args[2]; byte[] nonce = (byte[])args[3]; return(create(invoker, owners, theOperator, nonce)); } if (method == "depositNEP5") { BasicMethods.assert(args.Length == 4, "params length error"); byte[] invoker = (byte[])args[0]; byte[] walletId = (byte[])args[1]; byte[] tokenAddress = (byte[])args[2]; BigInteger amount = (BigInteger)args[3]; return(depositNEP5(invoker, walletId, tokenAddress, amount)); } if (method == "withdraw") { BasicMethods.assert(args.Length == 4, "params length error"); byte[] invoker = (byte[])args[0]; byte[] tokenAddress = (byte[])args[1]; byte[] receiver = (byte[])args[2]; BigInteger amount = (BigInteger)args[3]; return(withdraw(invoker, tokenAddress, receiver, amount)); } if (method == "transferToWallet") { BasicMethods.assert(args.Length == 5, "params length error"); byte[] fromWalletId = (byte[])args[0]; byte[] toWalletId = (byte[])args[1]; byte[] tokenAddress = (byte[])args[2]; byte[] receiver = (byte[])args[3]; BigInteger amount = (BigInteger)args[4]; return(transferToWallet(fromWalletId, toWalletId, tokenAddress, receiver, amount)); } if (method == "transferOperatorship") { BasicMethods.assert(args.Length == 2, "params length error"); byte[] walletId = (byte[])args[0]; byte[] newOperator = (byte[])args[1]; return(transferOperatorship(walletId, newOperator)); } if (method == "proposeNewOperator") { BasicMethods.assert(args.Length == 3, "params length error"); byte[] invoker = (byte[])args[0]; byte[] walletId = (byte[])args[1]; byte[] newOperator = (byte[])args[2]; return(proposeNewOperator(invoker, walletId, newOperator)); } if (method == "drainToken") { BasicMethods.assert(args.Length == 3, "params length error"); byte[] invoker = (byte[])args[0]; byte[] tokenAddress = (byte[])args[1]; byte[] receiver = (byte[])args[2]; BigInteger amount = (BigInteger)args[3]; return(drainToken(invoker, tokenAddress, receiver, amount)); } if (method == "getWalletOwners") { BasicMethods.assert(args.Length == 1, "params length error"); byte[] walletId = (byte[])args[0]; return(getWalletOwners(walletId)); } if (method == "getOperator") { BasicMethods.assert(args.Length == 1, "params length error"); byte[] walletId = (byte[])args[0]; return(getOperator(walletId)); } if (method == "getBalance") { BasicMethods.assert(args.Length == 2, "params length error"); byte[] walletId = (byte[])args[0]; byte[] tokenAddress = (byte[])args[1]; return(getBalance(walletId, tokenAddress)); } if (method == "getProposalVote") { BasicMethods.assert(args.Length == 2, "params length error"); byte[] walletId = (byte[])args[0]; byte[] owner = (byte[])args[1]; return(getProposalVote(walletId, owner)); } } return(false); }
private static void _onlyPauser(byte[] invoker) { BasicMethods.assert(isPauser(invoker), "the invoker is not one effective pauser"); }
public static void _onlyWalletOwner(byte[] _walletId, byte[] _addr) { BasicMethods.assert(_isWalletOwner(_walletId, _addr), "Given address is not wallet owner"); }
public static void _onlyOperator(byte[] _walletId) { BasicMethods.assert(Runtime.CheckWitness(getWallet(_walletId).theOperator), "operator checkwitness failed"); //byte[] theOperator = getWallet(_walletId).theOperator; //assert(_invoker == theOperator, "msg.sender is not operator"); }