// FHIRTransactionBundle returns a FHIR bundle representing a transaction to post all patient data to a server
185799
func (p *Patient) FHIRTransactionBundle(conditionalUpdate bool) *fhir.Bundle {
	bundle := new(fhir.Bundle)
	bundle.Type = "transaction"
	fhirModels := p.FHIRModels()
	bundle.Entry = make([]fhir.BundleEntryComponent, len(fhirModels))
	for i := range fhirModels {
		bundle.Entry[i].FullUrl = "urn:uuid:" + reflect.ValueOf(fhirModels[i]).Elem().FieldByName("Id").String()
		bundle.Entry[i].Resource = fhirModels[i]
		bundle.Entry[i].Request = &fhir.BundleEntryRequestComponent{
			Method: "POST",
			Url:    reflect.TypeOf(fhirModels[i]).Elem().Name(),
		}
	}
	if conditionalUpdate {
		if err := ConvertToConditionalUpdates(bundle); err != nil {
			log.Println("Error:", err.Error())
		}
	}
	return bundle
}
1258768
func (api *API) BroadcastBundle(tailTxHash Hash) ([]Trytes, error) {
	if err := Validate(ValidateTransactionHashes(tailTxHash)); err != nil {
		return nil, err
	}

	bndl, err := api.GetBundle(tailTxHash)
	if err != nil {
		return nil, err
	}
	trytes := transaction.MustFinalTransactionTrytes(bndl)
	return api.BroadcastTransactions(trytes...)
}
221909
func (r Billing_Item_Virtual_DedicatedHost) GetBundleItems() (resp []datatypes.Product_Item_Bundles, err error) {
	err = r.Session.DoRequest("SoftLayer_Billing_Item_Virtual_DedicatedHost", "getBundleItems", nil, &r.Options, &resp)
	return
}
719952
func (r *rpcServer) SubscribeTransactions(req *lnrpc.GetTransactionsRequest,
	updateStream lnrpc.Lightning_SubscribeTransactionsServer) error {

	txClient, err := r.server.cc.wallet.SubscribeTransactions()
	if err != nil {
		return err
	}
	defer txClient.Cancel()

	for {
		select {
		case tx := <-txClient.ConfirmedTransactions():
			detail := &lnrpc.Transaction{
				TxHash:           tx.Hash.String(),
				Amount:           int64(tx.Value),
				NumConfirmations: tx.NumConfirmations,
				BlockHash:        tx.BlockHash.String(),
				TimeStamp:        tx.Timestamp,
				TotalFees:        tx.TotalFees,
			}
			if err := updateStream.Send(detail); err != nil {
				return err
			}

		case tx := <-txClient.UnconfirmedTransactions():
			detail := &lnrpc.Transaction{
				TxHash:    tx.Hash.String(),
				Amount:    int64(tx.Value),
				TimeStamp: tx.Timestamp,
				TotalFees: tx.TotalFees,
			}
			if err := updateStream.Send(detail); err != nil {
				return err
			}

		case <-r.quit:
			return nil
		}
	}
}
414439
func (ec *Client) SendTransaction(ctx context.Context, tx *types.Transaction) error {
	data, err := rlp.EncodeToBytes(tx)
	if err != nil {
		return err
	}
	return ec.c.CallContext(ctx, nil, "eth_sendRawTransaction", common.ToHex(data))
}
1045167
func parseBundle(data []byte, sender net.Addr, limit int32) (Bundle, error) {
	b := Bundle{}

	// If 0 <= limit < 16 this is an error.
	// We have to be able to read at least the bundle tag and a timetag.
	if (limit >= 0) && (limit < int32(len(BundleTag)+1+TimetagSize)) {
		return b, errors.New("limit must be >= 16 or < 0")
	}

	data, err := sliceBundleTag(data)
	if err != nil {
		return b, errors.Wrap(err, "slice bundle tag")
	}

	tt, err := ReadTimetag(data)
	if err != nil {
		return b, errors.Wrap(err, "read timetag")
	}
	b.Timetag = tt
	data = data[8:]

	// We are limited to only reading the bundle tag and the timetag.
	if limit == 16 {
		return b, nil
	}

	// We take away 16 from limit so that readPackets doesn't have to know we have already read 16 bytes.
	packets, err := readPackets(data, sender, limit-16)
	if err != nil {
		return b, errors.Wrap(err, "read packets")
	}
	b.Packets = packets

	return b, nil
}
626789
func (api *PublicFilterAPI) NewPendingTransactions(ctx context.Context) (*rpc.Subscription, error) {
	notifier, supported := rpc.NotifierFromContext(ctx)
	if !supported {
		return &rpc.Subscription{}, rpc.ErrNotificationsUnsupported
	}

	rpcSub := notifier.CreateSubscription()

	go func() {
		txHashes := make(chan []common.Hash, 128)
		pendingTxSub := api.events.SubscribePendingTxs(txHashes)

		for {
			select {
			case hashes := <-txHashes:
				// To keep the original behaviour, send a single tx hash in one notification.
				// TODO(rjl493456442) Send a batch of tx hashes in one notification
				for _, h := range hashes {
					notifier.Notify(rpcSub.ID, h)
				}
			case <-rpcSub.Err():
				pendingTxSub.Unsubscribe()
				return
			case <-notifier.Closed():
				pendingTxSub.Unsubscribe()
				return
			}
		}
	}()

	return rpcSub, nil
}
6857
func AddEntry(txs Bundle, bndlEntry BundleEntry) Bundle {
	bndlEntry = getBundleEntryWithDefaults(bndlEntry)
	prevLastIndex := uint64(len(txs))
	lastIndex := uint64(len(txs)-1) + bndlEntry.Length
	tag := PadTag(bndlEntry.Tag)

	// set new last index on existing txs
	for i := range txs {
		txs[i].LastIndex = lastIndex
	}

	var i uint64
	for ; i < bndlEntry.Length; i++ {
		var v int64
		if i == 0 {
			v = bndlEntry.Value
		}
		txs = append(txs, transaction.Transaction{
			Address: bndlEntry.Address,
			Value:   v, Tag: tag, ObsoleteTag: tag,
			CurrentIndex: prevLastIndex + i,
			LastIndex:    lastIndex, Timestamp: bndlEntry.Timestamp,
			SignatureMessageFragment: bndlEntry.SignatureMessageFragments[i],
			TrunkTransaction:         NullHashTrytes, BranchTransaction: NullHashTrytes,
			Bundle: NullHashTrytes, Nonce: NullNonceTrytes, Hash: NullHashTrytes,
		})
	}

	return txs
}
653042
func (pgb *ChainDB) SpendingTransaction(fundingTxID string,
	fundingTxVout uint32) (string, uint32, int8, error) {
	ctx, cancel := context.WithTimeout(pgb.ctx, pgb.queryTimeout)
	defer cancel()
	_, spendingTx, vinInd, tree, err := RetrieveSpendingTxByTxOut(ctx, pgb.db, fundingTxID, fundingTxVout)
	return spendingTx, vinInd, tree, pgb.replaceCancelError(err)
}
460871
func NewBundle(channelID string, config *cb.Config) (*Bundle, error) {
	if err := preValidate(config); err != nil {
		return nil, err
	}

	channelConfig, err := NewChannelConfig(config.ChannelGroup)
	if err != nil {
		return nil, errors.Wrap(err, "initializing channelconfig failed")
	}

	policyProviderMap := make(map[int32]policies.Provider)
	for pType := range cb.Policy_PolicyType_name {
		rtype := cb.Policy_PolicyType(pType)
		switch rtype {
		case cb.Policy_UNKNOWN:
			// Do not register a handler
		case cb.Policy_SIGNATURE:
			policyProviderMap[pType] = cauthdsl.NewPolicyProvider(channelConfig.MSPManager())
		case cb.Policy_MSP:
			// Add hook for MSP Handler here
		}
	}

	policyManager, err := policies.NewManagerImpl(RootGroupKey, policyProviderMap, config.ChannelGroup)
	if err != nil {
		return nil, errors.Wrap(err, "initializing policymanager failed")
	}

	configtxManager, err := configtx.NewValidatorImpl(channelID, config, RootGroupKey, policyManager)
	if err != nil {
		return nil, errors.Wrap(err, "initializing configtx manager failed")
	}

	return &Bundle{
		policyManager:   policyManager,
		channelConfig:   channelConfig,
		configtxManager: configtxManager,
	}, nil
}
1090761
func transaction(db *sql.DB, f func(*sql.Tx) error) (err error) {
	if db == nil {
		panic("darwin: sql.DB is nil")
	}

	tx, err := db.Begin()

	if err != nil {
		return
	}

	defer func() {
		if p := recover(); p != nil {
			switch p := p.(type) {
			case error:
				err = p
			default:
				err = fmt.Errorf("%s", p)
			}
		}
		if err != nil {
			tx.Rollback()
			return
		}
		err = tx.Commit()
	}()

	return f(tx)
}
751037
func (s *S3Location) SetBundleType(v string) *S3Location {
	s.BundleType = &v
	return s
}
575218
func deployBundle(
	bundleDir string,
	data *charm.BundleData,
	bundleURL *charm.URL,
	bundleOverlayFile []string,
	channel csparams.Channel,
	apiRoot DeployAPI,
	ctx *cmd.Context,
	bundleStorage map[string]map[string]storage.Constraints,
	bundleDevices map[string]map[string]devices.Constraints,
	dryRun bool,
	useExistingMachines bool,
	bundleMachines map[string]string,
) (map[*charm.URL]*macaroon.Macaroon, error) {

	if err := composeBundle(data, ctx, bundleDir, bundleOverlayFile); err != nil {
		return nil, errors.Trace(err)
	}
	if err := verifyBundle(data, bundleDir); err != nil {
		return nil, errors.Trace(err)
	}

	// TODO: move bundle parsing and checking into the handler.
	h := makeBundleHandler(dryRun, bundleDir, channel, apiRoot, ctx, data, bundleURL, bundleStorage, bundleDevices)
	if err := h.makeModel(useExistingMachines, bundleMachines); err != nil {
		return nil, errors.Trace(err)
	}
	if err := h.resolveCharmsAndEndpoints(); err != nil {
		return nil, errors.Trace(err)
	}
	if err := h.getChanges(); err != nil {
		return nil, errors.Trace(err)
	}
	if err := h.handleChanges(); err != nil {
		return nil, errors.Trace(err)
	}
	return h.macaroons, nil

}
558897
func (mc *multiProvider) SaveFullCommit(fc FullCommit) (err error) {
	for _, p := range mc.providers {
		err = p.SaveFullCommit(fc)
		if err != nil {
			return
		}
	}
	return
}
1334152
func composeBundle(data *charm.BundleData, ctx *cmd.Context, bundleDir string, overlayFileNames []string) error {
	if err := processBundleOverlay(data, overlayFileNames...); err != nil {
		return errors.Annotate(err, "unable to process overlays")
	}
	if bundleDir == "" {
		bundleDir = ctx.Dir
	}
	if err := processBundleIncludes(bundleDir, data); err != nil {
		return errors.Annotate(err, "unable to process includes")
	}
	return nil
}
1131317
func (vtg *VTGate) ResolveTransaction(ctx context.Context, dtid string) error {
	return formatError(vtg.txConn.Resolve(ctx, dtid))
}
679024
func (c *Client) Bundle(certResp *CertificateResponse) (bundledPEM []byte, err error) {
	if !certResp.IsAvailable() {
		return nil, errors.New("Cannot bundle without certificate")
	}

	if certResp.Issuer == "" {
		return nil, errors.New("Could not bundle certificates. Issuer not found")
	}

	resp, err := c.client.Get(certResp.Issuer)
	if err != nil {
		return nil, fmt.Errorf("Error requesting issuer certificate: %s", err)
	}
	defer resp.Body.Close()

	issuerDER, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, fmt.Errorf("Error reading issuer certificate: %s", err)
	}

	certPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: certResp.Certificate.Raw})
	issuerPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: issuerDER})

	return append(certPEM, issuerPEM...), nil
}