@param string      $chainName
@param array       $trxParams
@param null|Buffer $byteBuffer

@return null|string|Buffer
@throws \Exception
549215
public static function serializeTransaction($chainName, $trxParams, $byteBuffer = null)
    {
        $buffer = $byteBuffer === null ? (new ByteBuffer()) : $byteBuffer;

        $buffer->writeInt16LE($trxParams[0]['ref_block_num'], 0);
        $buffer->writeInt32LE($trxParams[0]['ref_block_prefix'], 2);
        $expirationSec = is_int($trxParams[0]['expiration']) ? $trxParams[0]['expiration'] : strtotime($trxParams[0]['expiration']);
        $buffer->writeInt32LE($expirationSec, 6);
        $buffer->writeInt8(count($trxParams[0]['operations']));


        //serialize only operations data
        foreach ($trxParams[0]['operations'] as $operation) {
            $opData = $operation[1];
            self::serializeOperation($chainName, $operation[0], $opData, $buffer);
        }


        $buffer->writeInt8(count($trxParams[0]['extensions']));
        foreach ($trxParams[0]['extensions'] as $extansion) {
            //is it used anywhere?
        }

        return $byteBuffer === null ? $buffer->getBuffer('H', 0, $buffer->getCurrentOffset()) : $byteBuffer;
    }
1206505
public void setChaincodeVersion(String chaincodeVersion) throws InvalidArgumentException {
        if (Utils.isNullOrEmpty(chaincodeVersion)) {
            throw new InvalidArgumentException("The chaincodeVersion parameter can not be null or empty.");
        }
        this.chaincodeVersion = chaincodeVersion;

    }
566091
private function compareTraceFrameParam($paramName, array $traceFrame1, array $traceFrame2)
    {
        $param1 = isset($traceFrame1[$paramName]) ? $traceFrame1[$paramName] : null;
        $param2 = isset($traceFrame2[$paramName]) ? $traceFrame2[$paramName] : null;

        return $param1 === $param2;
    }
583044
protected function startRenderBlock($blockName, $segmentText)
    {
        foreach ($this->plugins as $plugin) {
            $blockRenderList = $plugin->getBlockRenderList();
            if (in_array($blockName, $blockRenderList) === true) {
                echo $plugin->callBlockRenderStart($blockName, $segmentText);
                ob_start();
                return;
            }
        }
        throw new JigException("Block $blockName not known for starting block in plugins.");
    }
1189906
@Override
    public synchronized ChainGroupData[] getAllChainGroups(String chainName) throws ChainException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "getAllChainGroups chainName=" + chainName);
        }
        if (null == chainName) {
            throw new InvalidChainNameException("Null chain name");
        }

        // Ensure the chain exists.
        ChainData chain = this.chainDataMap.get(chainName);
        if (null == chain) {
            throw new ChainException("Unable to find chain: " + chainName);
        }

        int index = 0;
        int numGroups = getNumGroupsUsingChain(chainName);
        ChainGroupData[] groupArray = new ChainGroupData[numGroups];
        for (ChainGroupData group : this.chainGroups.values()) {
            if (group.containsChain(chainName)) {
                groupArray[index++] = group;
            }
        }
        return groupArray;
    }
45362
@Override
    public void chainUpdated(ChainData chainData) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "chainUpdated", chainData);
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "chainUpdated");

    }
484288
@Override
    public int getListeningPort(String chainName) throws ChainException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(tc, "getListeningPort: " + chainName);
        }

        int listeningPort = -1;
        // Search the runtime chain list for the specified chain.
        Chain chain = this.chainRunningMap.get(chainName);
        if (null == chain) {
            throw new ChainException("Chain " + chainName + " not found in runtime.");
        }
        // Found the chain. Pull out the data on the chain.
        ChainData chainData = chain.getChainData();
        if (chainData.getType().equals(FlowType.INBOUND)) {
            ChannelData channelData = chainData.getChannelList()[0];
            Map<Object, Object> channelProperties = channelData.getPropertyBag();
            if (channelProperties != null) {
                String portString = (String) channelProperties.get(ChannelFrameworkConstants.PORT);
                if (portString != null && !portString.trim().equals("0")) {
                    listeningPort = Integer.parseInt(portString);
                } else {
                    // Port is not directly set. Check listenPort (in cases where port is
                    // config'd as *.
                    portString = (String) channelProperties.get(ChannelFrameworkConstants.LISTENING_PORT);
                    if (portString != null) {
                        listeningPort = Integer.parseInt(portString);
                    } else {
                        throw new ChainException("Chain " + chainName + " has no port in the device channel properties.");
                    }
                }
            } else {
                throw new ChainException("Chain " + chainName + " has no properties.");
            }
        } else {
            throw new ChainException("Chain " + chainName + " is not inbound.");
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(tc, "getListeningPort: " + listeningPort);
        }
        return listeningPort;
    }
963697
public synchronized Channel getRunningChannel(String inputChannelName, Chain chain) {
        if (inputChannelName == null || chain == null) {
            return null;
        }

        Channel channel = null;
        // Ensure the chain is running.
        if (null != this.chainRunningMap.get(chain.getName())) {
            ChannelData[] channels = chain.getChannelsData();
            for (int index = 0; index < channels.length; index++) {
                if (channels[index].getExternalName().equals(inputChannelName)) {
                    channel = chain.getChannels()[index];
                    break;
                }
            }
        }
        return channel;
    }
685595
@Override
    public synchronized ChainData getChain(String chainName) {
        ChainData chainData = null;
        // Ensure the input chain name is not null
        if (null != chainName) {
            chainData = this.chainDataMap.get(chainName);
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "getChain: " + chainName + " found=" + (null != chainData));
        }
        return chainData;
    }
75922
@Override
    public synchronized ChainData[] getAllChains(Class<?> factoryClass) throws InvalidChannelFactoryException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(tc, "getAllChains(factory)");
        }
        if (null == factoryClass) {
            throw new InvalidChannelFactoryException("Null factory class found");
        }

        String inputFactoryClassName = factoryClass.getName();
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "factory=" + inputFactoryClassName);
        }

        // Collect all chains referring to the channel
        List<ChainData> chainDataList = new ArrayList<ChainData>();
        ChannelData[] channels = null;
        for (ChainData chainData : this.chainDataMap.values()) {
            // Look at each channel associated with this chain.
            channels = chainData.getChannelList();
            for (int i = 0; i < channels.length; i++) {
                if (channels[i].getFactoryType().getName().equals(inputFactoryClassName)) {
                    chainDataList.add(chainData);
                }
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(tc, "getAllChains");
        }
        return chainDataList.toArray(new ChainData[chainDataList.size()]);
    }
1346453
private static Chain isKnownChain(String chainID, List<Chain> chains){

		for (int i = 0; i< chains.size();i++){
			Chain testchain =  chains.get(i);
			if (chainID.equals(testchain.getName())) {
				return testchain;
			}
		}

		return null;
	}
1068271
@SuppressWarnings("unchecked")
    public HttpServletRequest getChainedRequest() throws IOException, ServletException{
        if (super.containsError())
        {
            throw super.getError();
        }
        ChainedRequest req = new ChainedRequest(this, _req);
        //transfer any auto transfer headers
        Hashtable headers = getAutoTransferringHeaders();
        Enumeration names = headers.keys();
        while (names.hasMoreElements())
        {
            String name = (String)names.nextElement();
            String value = (String)headers.get(name);
            req.setHeader(name, value);
        }

        //get headers from response and add to request
        Iterable<String> headerNames = getHeaderNames();
        for (String name:headerNames)
        {
            String value = (String)getHeader(name);
            req.setHeader(name, value);
        }


        return req;
    }
16931
def db_chainstate_get_block(cls, cur, block_height):
        
        query = 'SELECT * FROM chainstate WHERE block_id = ? ORDER BY vtxindex;'
        args = (block_height,)

        rows = cls.db_query_execute(cur, query, args, verbose=False)
        ret = []

        for r in rows:
            rowdata = {
                'txid': str(r['txid']),
                'block_id': r['block_id'],
                'txindex': r['txindex'],
                'vtxindex': r['vtxindex'],
                'opcode': str(r['opcode']),
                'data_hex': str(r['data_hex']),
                'senders': simplejson.loads(r['senders']),
                'tx_hex': str(r['tx_hex']),
                'tx_merkle_path': str(r['tx_merkle_path']),
                'fee': r['fee']
            }

            ret.append(rowdata)

        return ret
1253231
private function parseChain($chain = []): void
    {
        if (!\is_array($chain)) {
            throw new InvalidArgumentException('Validators chain must be an array');
        }
        foreach ($chain as $k => $v) {
            if ($v instanceof AbstractSpecific) {
                // value is an instance of AbstractSpecific
                $reflection = new \ReflectionClass($v);
                $name = \str_replace($reflection->getNamespaceName().'\\', '', $reflection->getName());
                $this->chain[$name] = $v;
            } elseif (\is_string($k) && \is_array($v)) {
                // key is a string (validator name) and value is an array (validator options)
                $className = '\\MS\\LightFramework\\Validator\\Specific\\'.$k;
                if (!\class_exists($className)) {
                    throw new InvalidArgumentException('Validator "'.$k.'" not found');
                }
                $this->chain[$k] = new $className($v);
            } elseif (\is_numeric($k) && \is_array($v)) {
                // key is a numeric and value is an array (validator name => validator options)
                $this->parseChain($v);
            } else {
                // incorrect chain format
                $exMsg = 'Validator chain element must be either instance of AbstractValidator ';
                $exMsg .= 'or array("validatorName" => array(options))';
                throw new InvalidArgumentException($exMsg);
            }
        }
    }
1096017
public function buildTx(TransactionBuilder $txBuilder) {
        $send = $txBuilder->getOutputs();
        $utxos = $txBuilder->getUtxos();
        $signInfo = [];

        $txb = new TxBuilder();

        foreach ($utxos as $utxo) {
            if (!$utxo->address || !$utxo->value || !$utxo->scriptPubKey) {
                $tx = $this->sdk->transaction($utxo->hash);

                if (!$tx || !isset($tx['outputs'][$utxo->index])) {
                    throw new \Exception("Invalid output [{$utxo->hash}][{$utxo->index}]");
                }

                $output = $tx['outputs'][$utxo->index];

                if (!$utxo->address) {
                    $utxo->address = $this->addressReader->fromString($output['address']);
                }
                if (!$utxo->value) {
                    $utxo->value = $output['value'];
                }
                if (!$utxo->scriptPubKey) {
                    $utxo->scriptPubKey = ScriptFactory::fromHex($output['script_hex']);
                }
            }

            if (SignInfo::MODE_SIGN === $utxo->signMode) {
                if (!$utxo->path) {
                    $utxo->path = $this->getPathForAddress($utxo->address->getAddress());
                }

                if (!$utxo->redeemScript || !$utxo->witnessScript) {
                    list(, $redeemScript, $witnessScript) = $this->getRedeemScriptByPath($utxo->path);
                    $utxo->redeemScript = $redeemScript;
                    $utxo->witnessScript = $witnessScript;
                }
            }

            $signInfo[] = $utxo->getSignInfo();
        }

        $utxoSum = array_sum(array_map(function (UTXO $utxo) {
            return $utxo->value;
        }, $utxos));
        if ($utxoSum < array_sum(array_column($send, 'value'))) {
            throw new \Exception("Atempting to spend more than sum of UTXOs");
        }

        list($fee, $change) = $this->determineFeeAndChange($txBuilder, $this->getHighPriorityFeePerKB(), $this->getOptimalFeePerKB(), $this->getLowPriorityFeePerKB());

        if ($txBuilder->getValidateFee() !== null) {
            // sanity check to make sure the API isn't giving us crappy data
            if (abs($txBuilder->getValidateFee() - $fee) > (Wallet::BASE_FEE * 5)) {
                throw new \Exception("the fee suggested by the coin selection ({$txBuilder->getValidateFee()}) seems incorrect ({$fee})");
            }
        }

        if ($change > 0) {
            $send[] = [
                'address' => $txBuilder->getChangeAddress() ?: $this->getNewChangeAddress(),
                'value' => $change
            ];
        }

        foreach ($utxos as $utxo) {
            $txb->spendOutPoint(new OutPoint(Buffer::hex($utxo->hash), $utxo->index));
        }

        // outputs should be randomized to make the change harder to detect
        if ($txBuilder->shouldRandomizeChangeOuput()) {
            $this->sdk->shuffle($send);
        }

        foreach ($send as $out) {
            assert(isset($out['value']));

            if (isset($out['scriptPubKey'])) {
                $txb->output($out['value'], $out['scriptPubKey']);
            } elseif (isset($out['address'])) {
                $txb->output($out['value'], $this->addressReader->fromString($out['address'])->getScriptPubKey());
            } else {
                throw new \Exception();
            }
        }

        return [$txb->get(), $signInfo];
    }
1106391
public void addChain(ChainData newChain) throws ChainException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(tc, "addChain: " + newChain.getName());
        }

        if (containsChain(newChain.getName())) {
            ChainException e = new ChainException("Chain already exists: " + newChain.getName());
            FFDCFilter.processException(e, getClass().getName() + ".addChain", "116", this, new Object[] { newChain });
            throw e;
        }

        // Create a chain array that is one element bigger than the current one.
        int currentLength = this.chainArray.length;
        ChainData[] newChains = new ChainData[currentLength + 1];
        // Copy the existing elements to the new array.
        System.arraycopy(getChains(), 0, newChains, 0, currentLength);
        // Add the new chain to the end of the new list.
        newChains[currentLength] = newChain;
        // Update this group's chain list
        setChains(newChains);
        // Add all group listeners to this chain. If some already exist,
        // this doesn't break anything.
        for (ChainEventListener listener : getChainEventListeners()) {
            ((ChainDataImpl) newChain).addChainEventListener(listener);
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(tc, "addChain");
        }
    }
932436
@Override
    public synchronized ChainData updateChain(String chainName, String[] newChannelList) throws ChannelException, ChainException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(tc, "updateChain: " + chainName);
        }
        if (null == chainName) {
            throw new InvalidChainNameException("Null chain name");
        }
        if ((null == newChannelList) || (0 == newChannelList.length)) {
            throw new InvalidChannelNameException("Null or empty channel list");
        }
        // Verify chain config exists.
        ChainDataImpl oldChainData = chainDataMap.get(chainName);
        if (null == oldChainData) {
            InvalidChainNameException e = new InvalidChainNameException("Unable to update unknown chain, " + chainName);
            FFDCFilter.processException(e, getClass().getName() + ".updateChain", "1724", this, new Object[] { chainName });
            throw e;
        }

        // Verify the chain config is not currently in use by the runtime.
        Chain chain = chainRunningMap.get(chainName);
        if (chain != null) {
            ChainException e = new ChainException("Unable to update runtime chain " + chainName + ".  Destroy chain first.");
            FFDCFilter.processException(e, getClass().getName() + ".updateChain", "1733", this, new Object[] { chain });
            throw e;
        }

        // Verify all channel configs were found in the framework.
        ChannelData[] newChannelData = new ChannelData[newChannelList.length];
        for (int i = 0; i < newChannelList.length; i++) {
            // Build up list of new channel configs for the new chain.
            newChannelData[i] = channelDataMap.get(newChannelList[i]);
            if (null == newChannelData[i]) {
                InvalidChannelNameException e = new InvalidChannelNameException("Unable to update chain config with unknown channel, " + newChannelList[i]);
                FFDCFilter.processException(e, getClass().getName() + ".updateChain", "1752", this, new Object[] { newChannelList[i] });
                throw e;
            }
        }

        // Ensure that new configuration is different from old one.
        ChannelData[] oldChannelDataArray = oldChainData.getChannelList();
        boolean configurationDifferent = true;
        if (oldChannelDataArray.length == newChannelData.length) {
            // Same number of channelRunningMap. Now look for exact same
            // channelRunningMap.
            String oldChannelName = null;
            String newChannelName = null;
            boolean foundOldChannel = false;
            configurationDifferent = false;
            for (int j = 0; j < oldChannelDataArray.length; j++) {
                oldChannelName = oldChannelDataArray[j].getName();
                foundOldChannel = false;
                for (int k = 0; k < newChannelData.length; k++) {
                    newChannelName = newChannelData[k].getName();
                    if (oldChannelName.equals(newChannelName)) {
                        foundOldChannel = true;
                        break;
                    }
                }
                if (!foundOldChannel) {
                    // Never found the old channel in the new channel list.
                    configurationDifferent = true;
                    break;
                }
            }
        }
        if (!configurationDifferent) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Identical channel list, no update");
            }
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
                Tr.exit(tc, "updateChain");
            }
            return oldChainData;
        }

        // Create the new chain configuration object with the input chain name.
        ChainDataImpl newChainData = null;
        try {
            newChainData = (ChainDataImpl) createChainData(chainName, FlowType.INBOUND, newChannelData, oldChainData.getPropertyBag());
        } catch (IncoherentChainException e) {
            FFDCFilter.processException(e, getClass().getName() + ".updateChain", "1792", this, new Object[] { chainName, newChannelData });
            throw e;
        }

        // Ensure existing listeners in old chain config move to new chain config.
        newChainData.setChainEventListeners(oldChainData.removeAllChainEventListeners());
        // Create or swap in new chain config.
        this.chainDataMap.put(chainName, newChainData);

        // Update any chain groups including this chain.
        ChainGroupDataImpl groupData = null;
        Iterator<ChainGroupData> groupIter = chainGroups.values().iterator();
        while (groupIter.hasNext()) {
            groupData = (ChainGroupDataImpl) groupIter.next();
            if (groupData.containsChain(chainName)) {
                groupData.updateChain(newChainData);
            }
        }

        // Alert the chain event listener.
        newChainData.chainUpdated();

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(tc, "updateChain");
        }
        return newChainData;
    }