func (server *OpencxServer) withdrawFromChain(params *coinparam.Params) (withdrawFunction func(string, *koblitz.PublicKey, uint64) (string, error), err error) {
	wallet, found := server.WalletMap[params]
	if !found {
		err = fmt.Errorf("Could not find wallet for those coin params")
		return
	}
	withdrawFunction = func(address string, pubkey *koblitz.PublicKey, amount uint64) (txid string, err error) {
		if amount == 0 {
			err = fmt.Errorf("You can't withdraw 0 %s", params.Name)
			return
		}
		if err = server.CreditUser(pubkey, amount, params); err != nil {
			err = fmt.Errorf("Error while crediting user for CreateChannel: %s\n", err)
			return
		}
		var addr btcutil.Address
		if addr, err = btcutil.DecodeAddress(address, params); err != nil {
			return
		}
		var payToUserScript []byte
		if payToUserScript, err = txscript.PayToAddrScript(addr); err != nil {
			return
		}
		var utxoSlice portxo.TxoSliceByBip69
		var overshoot int64
		if utxoSlice, overshoot, err = wallet.PickUtxos(int64(amount), int64(len(payToUserScript)), 1000, false); err != nil {
			return
		}
		var changeOut *wire.TxOut
		if changeOut, err = wallet.NewChangeOut(overshoot); err != nil {
			return
		}
		payToUserTxOut := wire.NewTxOut(int64(amount), payToUserScript)
		var withdrawTx *wire.MsgTx
		if withdrawTx, err = wallet.BuildAndSign(utxoSlice, []*wire.TxOut{changeOut, payToUserTxOut}, 0); err != nil {
			return
		}
		buf := new(bytes.Buffer)
		if err = withdrawTx.Serialize(buf); err != nil {
			return
		}
		if err = wallet.NewOutgoingTx(withdrawTx); err != nil {
			return
		}
		return withdrawTx.TxHash().String(), nil
	}
	return
}
withdrawFromChain returns a function that we'll then call from the vtc stuff -- this is a closure that's also a method for server, don't worry about it lol
package cxserver
import (
	"bytes"
	"fmt"
	"github.com/mit-dci/lit/consts"
	"github.com/mit-dci/lit/lnp2p"
	"github.com/mit-dci/lit/qln"
	"github.com/mit-dci/opencx/logging"
	"github.com/mit-dci/lit/lnutil"
	"github.com/mit-dci/lit/coinparam"
	"github.com/mit-dci/lit/crypto/koblitz"
	"github.com/mit-dci/lit/portxo"
	"github.com/mit-dci/lit/wire"
	"github.com/mit-dci/lit/btcutil/txscript"
	"github.com/mit-dci/lit/btcutil"
)
func (server *OpencxServer) WithdrawCoins(address string, pubkey *koblitz.PublicKey, amount uint64, params *coinparam.Params) (txid string, err error) {
	if int64(amount) < 0 {
		err = fmt.Errorf("That amount would have caused an overflow, enter something lower")
		return
	}
	var withdrawFunction func(string, *koblitz.PublicKey, uint64) (string, error)
	if withdrawFunction, err = server.withdrawFromChain(params); err != nil {
		err = fmt.Errorf("Error creating withdraw function: \n%s", err)
		return
	}
	if txid, err = withdrawFunction(address, pubkey, amount); err != nil {
		err = fmt.Errorf("Error withdrawing coins: \n%s", err)
		return
	}
	return
}
func (server *OpencxServer) WithdrawLightning(pubkey *koblitz.PublicKey, amount uint64, params *coinparam.Params) (txid string, err error) {
	if int64(amount) < 0 {
		err = fmt.Errorf("That amount would have caused an overflow, enter something lower")
		return
	}
	var withdrawFunction func(*koblitz.PublicKey, int64) (string, error)
	if withdrawFunction, err = server.withdrawFromLightning(params); err != nil {
		err = fmt.Errorf("Error creating withdraw function: \n%s", err)
		return
	}
	if txid, err = withdrawFunction(pubkey, int64(amount)); err != nil {
		err = fmt.Errorf("Error withdrawing coins: \n%s", err)
		return
	}
	return
}