public static bool init(byte[] _payRegistryHash, byte[] _celerWalletHash) { BasicMethods.assert(BasicMethods._isLegalAddress(_payRegistryHash), "Pay registry contract hash illegal"); BasicMethods.assert(BasicMethods._isLegalAddress(_celerWalletHash), "celer wallet contract hash illegal"); LedgerStruct.Ledger ledger = new LedgerStruct.Ledger(); ledger.payRegistry = _payRegistryHash; ledger.celerWallet = _celerWalletHash; setLedger(ledger); LedgerBalanceLimit.enableBalanceLimitsInner(); return(true); }
public static byte[] migrateChannelToInner(byte[] sender, LedgerStruct.Ledger _self, byte[][] pubKeys, byte[] _migrationRequest) { BasicMethods.assert(BasicMethods._isLegalAddress(sender), "sender illegal"); PbChain.ChannelMigrationRequest migrationRequest = (PbChain.ChannelMigrationRequest)Neo.SmartContract.Framework.Helper.Deserialize(_migrationRequest); PbEntity.ChannelMigrationInfo migrationInfo = (PbEntity.ChannelMigrationInfo)Neo.SmartContract.Framework.Helper.Deserialize(migrationRequest.channelMigrationInfo); byte[] channelId = migrationInfo.channelId; BasicMethods.assert(BasicMethods._isByte32(channelId), "channelId illegal"); LedgerStruct.Channel c = LedgerStruct.getChannelMap(channelId); byte[] toLedgerAddr = migrationInfo.toLedgerAddress; LedgerStruct.ChannelStatus channelStatus = LedgerStruct.getStandardChannelStatus(); BasicMethods.assert( c.status == channelStatus.Operable || c.status == channelStatus.Settling, "status illegal" ); byte[] h = Hash256(migrationRequest.channelMigrationInfo); // use Channel Library instead BasicMethods.assert(LedgerChannel._checkCoSignatures(c, h, pubKeys, migrationRequest.sigs), "Check co-sigs failed"); BasicMethods.assert(migrationInfo.fromLedgerAddress.Equals(ExecutionEngine.ExecutingScriptHash), "From ledger address is not this"); BasicMethods.assert(toLedgerAddr.Equals(sender), "To ledger address is not msg.sender"); BasicMethods.assert(Blockchain.GetHeight() <= migrationInfo.migrationDeadline, "Passed migration deadline"); c = LedgerOperation._updateChannelStatus(c, channelStatus.Migrated); c.migratedTo = toLedgerAddr; LedgerStruct.setChannelMap(channelId, c); MigrateChannelToEvent(channelId, toLedgerAddr); byte[] celerWallet = _self.celerWallet; NEP5Contract dyncall = (NEP5Contract)celerWallet.ToDelegate(); Object[] args = new object[] { channelId, toLedgerAddr }; dyncall("transferOperatorship", args); return(channelId); }
public static bool migrateChannelFromInner(LedgerStruct.Ledger _self, byte[] _fromLedgerAddr, byte[] _migrationRequest, byte[][] pubKeys) { BasicMethods.assert(BasicMethods._isLegalAddress(_fromLedgerAddr), "_fromLedgerAddr illegal"); // TODO: latest version of openzeppelin Address.sol provide this api toPayable() byte[] fromLedgerAddrPayable = _fromLedgerAddr; NEP5Contract dyncall = (NEP5Contract)fromLedgerAddrPayable.ToDelegate(); Object[] args = new object[] { _migrationRequest, pubKeys }; byte[] channelId = (byte[])dyncall("migrateChannelTo", args); LedgerStruct.Channel c = LedgerStruct.getChannelMap(channelId); LedgerStruct.ChannelStatus channelStatus = LedgerStruct.getStandardChannelStatus(); BasicMethods.assert(c.status == channelStatus.Uninitialized, "Immigrated channel already exists"); byte[] celerWallet = _self.celerWallet; args = new object[] { channelId }; dyncall = (NEP5Contract)celerWallet.ToDelegate(); byte[] oper = (byte[])dyncall("getOperator", args); BasicMethods.assert( oper.Equals(ExecutionEngine.ExecutingScriptHash), "Operatorship not transferred" ); c = LedgerOperation._updateChannelStatus(c, channelStatus.Operable); // Do not migrate WithdrawIntent, in other words, migration will implicitly veto // pending WithdrawIntent if any. c = LedgerChannel._importChannelMigrationArgs(c, fromLedgerAddrPayable, channelId); c = LedgerChannel._importPeersMigrationInfo(c, fromLedgerAddrPayable, channelId); LedgerStruct.setChannelMap(channelId, c); MigrateChannelFromEvent(channelId, _fromLedgerAddr); return(true); }
private static void setLedger(LedgerStruct.Ledger ledger) { Storage.Put(Storage.CurrentContext, ledgerHashKey, Neo.SmartContract.Framework.Helper.Serialize(ledger)); }
private static LedgerStruct.Ledger getLedger() { byte[] result = Storage.Get(Storage.CurrentContext, ledgerHashKey); LedgerStruct.Ledger ledger = (LedgerStruct.Ledger)Neo.SmartContract.Framework.Helper.Deserialize(result); return(ledger); }
public static bool deposit(byte[] _sender, byte[] _channelId, byte[] _receiver, BigInteger _transferFromAmount) { LedgerStruct.Ledger ledger = getLedger(); LedgerOperation.depositInner(_sender, ledger, _channelId, _receiver, _transferFromAmount, LedgerBalanceLimit.getBalanceLimitsEnabledInner()); return(true); }
public static bool openChannel(byte[] _openRequest, byte[][] pubKeys) { LedgerStruct.Ledger ledger = getLedger(); LedgerOperation.openChannelInner(ledger, pubKeys, _openRequest, LedgerBalanceLimit.getBalanceLimitsEnabledInner()); return(true); }