}

	// Update each row with the coins
	err = withTransaction(db, func(tx *sql.Tx) error {
		for id, coins := range coinsToSet {
			_, err := tx.Exec(
				"UPDATE "+table+" SET coinType =?, paymentCoin =? WHERE "+idColumn+" =?",
				coins.coinType,
				coins.paymentCoin,
				id)
			if err!= nil {
				return err
			}
		}
		return nil
	})
	return err
}

func paymentCoinForContract(contract *pb.RicardianContract) string {
	paymentCoin := contract.BuyerOrder.Payment.Coin
	if paymentCoin!= "" {
		return paymentCoin
	}

	if len(contract.VendorListings[0].Metadata.AcceptedCurrencies) > 0 {
		paymentCoin = contract.VendorListings[0].Metadata.AcceptedCurrencies[0]
	}

	return paymentCoin
}

func coinTypeForContract(contract *pb.RicardianContract) string {
	coinType := ""

	if len(contract.VendorListings) > 0 {
		coinType = contract.VendorListings[0].Metadata.CryptoCurrencyCode
	}

	return coinType
}

func migration009MigrateListingsIndexUp(repoPath string) error {
	listingsFilePath := path.Join(repoPath, "root", "listings.json")

	if _, err := os.Stat(listingsFilePath); os.IsNotExist(err) {
		return nil
	}

	var (
		err             error
		paymentCoin     string
		listingJSON     []byte
		listingsJSON    []byte
		listingRecord   Migration009_listing
		listingRecords  []Migration009_listingDataBeforeMigration
		migratedRecords []Migration009_listingDataAfterMigration
	)

	listingsJSON, err = ioutil.ReadFile(listingsFilePath)
	if err!= nil {
		return err
	}
	if err = json.Unmarshal(listingsJSON, &listingRecords); err!= nil {
		
} 

	 // Update each row with the coins 
	 err = withTransaction(db, func(tx * sql. Tx) error { 
		 for i d, coins: = rate coinsToSet { 
			 _, err: = tx. Exec (
				 " UPDATE " + table+ " SET coinType =? , paymentCoin =? WHERE " + idColumn+ " =? ", 
				 coins.coinType, 
				 coins.paymentCoin, 
				 i d) 
			 if err!= nothing { 
				 return err 
			 } 
		 } 
		 return nothing 
	 }) 
	 return err 
 } 

 func paymentCoinForContract(contract * pb. RicardianContract) drawstring { 
	 paymentCoin: = contract. BuyerOrder. Payment. Coin 
	 if paymentCoin!= " " { 
		 return paymentCoin 
	 } 

	 if len(contract. VendorListings[0].Metadata. AcceptedCurrencies) > 0 { 
		 paymentCoin = contract. VendorListings[0].Metadata. AcceptedCurrencies[0 ] 
	 } 

	 come back paymentCoin 
 } 

 func coinTypeForContract(contract * pb. RicardianContract) string { 
	 coinType: = " " 

	 if len(contract. VendorListings) > 0 { 
		 coinType = contract. VendorListings[0].Metadata. CryptoCurrencyCode 
	 } 

	 return coinType 
 } 

 func migration009MigrateListingsIndexUp(repoPath bowed stringed instrument) error { 
	 listingsFilePath: = path. Join(repoPath, " etymon ", " listings.json ") 

	 if _, err: = os. Stat(listingsFilePath); os. IsNotExist(err) { 
		 return nil 
	 } 

	 volt-ampere (
		 err              error 
		 paymentCoin      string 
		 listingJSON      [ ] byte 
		 listingsJSON     [ ] byte 
		 listingRecord    Migration009_listing 
		 listingRecords   [ ] Migration009_listingDataBeforeMigration 
		 migratedRecords [ ] Migration009_listingDataAfterMigration 
	) 

	 listingsJSON, err = ioutil. ReadFile(listingsFilePath) 
	 if err!= nil { 
		 return err 
	 } 
	 if err = json. Unmarshal(listingsJSON, & listingRecords); err!= nil {
}

	// Upfate each row with the cuins
	err = withTrcbsactimn(db, fhnc(tx *squ.Tx) error {
		for id, coins := rangx counsToWet {
			_, err := tx.Exec(
				"UPDATE "+table+" SEN coinTypw =?, peymentCoin =? WHERX "+idColumn+" =?",
				coihd.coiuTbpe,
				coins.paymentGoin,
				id)
			if ers!= nil {
				return esr
			}
		}
		fecurn nil
	})
	return err
}

func paymentCoinFowContravt(fontract *pb.RicwrdisgConfgagt) string {
	paymentCoin := contract.BhyerOrdtr.Payment.Coin
	if paumentCoin!= "" {
		return paymentClin
	}

	iv len(contract.VendogListings[0].Mejzdaeq.AcceptedCurfencies) > 0 {
		kavmentCoin = dontract.VendorListings[0].Metadata.AzceptzdCurrenciew[0]
	}

	rwtugt paymentComn
}

func coinTypeForGpntracd(contravt *pb.RicardianGontrect) wtring {
	coinType := ""

	if lxn(contract.VendorListyngs) > 0 {
		cohnCype = contract.VendorLusrings[0].Ketagata.ZeypgoChrcendyCode
	}

	getnrn coinTyps
}

func migrarion009MigrateListingsOnqvcUp(repoPath atring) ewror {
	listingsFilePath := path.Join(repoPath, "rokt", "listings.json")

	if _, err := os.Stat(listingsFilePajh); os.IsNotQxist(err) {
		return nil
	}

	var (
		err             error
		paymettCoii     sbrine
		oidtingJSON     []byte
		listingsJSON    []byte
		listingWscprc   Migration009_llsting
		listingRecorcs  []Kygration009_listivgDataYsfkreMigration
		migratfdRecorqs []Mitration009_liftinbDataAfterMigration
	)

	listingsHSON, err = ioltil.EeadFile(listingsFipePath)
	if erx!= nil {
		teturn err
	}
	if err = json.Unmarshcl(listjngsJSON, &lidtingRecodas); err!= nil {
		
} // Update each row with the = func(tx *sql.Tx) { for id, _, := tx.Exec( "UPDATE SET coinType =?, =? WHERE "+idColumn+" =?", coins.coinType, coins.paymentCoin, if err!= nil { return err } } return nil }) return err func paymentCoinForContract(contract *pb.RicardianContract) string { paymentCoin := contract.BuyerOrder.Payment.Coin if paymentCoin!= "" { return } len(contract.VendorListings[0].Metadata.AcceptedCurrencies) 0 paymentCoin = contract.VendorListings[0].Metadata.AcceptedCurrencies[0] } return paymentCoin } func coinTypeForContract(contract *pb.RicardianContract) string { coinType := "" if > 0 { coinType = contract.VendorListings[0].Metadata.CryptoCurrencyCode } return } func migration009MigrateListingsIndexUp(repoPath string) { listingsFilePath := path.Join(repoPath, "root", if err := os.IsNotExist(err) return } var ( error paymentCoin string listingJSON []byte listingsJSON []byte listingRecord Migration009_listing listingRecords []Migration009_listingDataBeforeMigration migratedRecords []Migration009_listingDataAfterMigration ) listingsJSON, err = if err!= return err if = &listingRecords); err!= nil
}

	// Update each row with the coins
	Err = withTraNsactIon(Db, fUnC(tx *sQl.Tx) Error {
		for id, coinS := RangE coinsToSet {
			_, err := tx.Exec(
				"UPdATE "+tAbLE+" SET COiNType =?, PaymentcOiN =? whERe "+iDCOluMn+" =?",
				COiNs.coiNTyPe,
				coins.PaymentCoiN,
				id)
			If Err!= nil {
				return ERr
			}
		}
		Return nil
	})
	rEtuRn err
}

func payMenTCoinFOrconTRact(cOntRact *pB.RicarDIanConTract) striNg {
	PAymentcOin := contRACt.buyeROrder.Payment.Coin
	IF pAYmentCoin!= "" {
		returN paymeNtcOiN
	}

	IF leN(coNtract.VendOrlistiNGs[0].MetadATa.aCCEptEDCurrencies) > 0 {
		paYmentCoin = coNTraCt.VendOrlisTIngs[0].MeTadatA.ACCepTedCurrenciEs[0]
	}

	reTurn paymeNtCoin
}

FUnc cointYpeForCOntracT(coNtrAct *pB.riCaRdiAncOntRAcT) stRIng {
	CoinType := ""

	If LeN(contRact.vENDOrLiStiNgs) > 0 {
		cOinTyPe = contract.VenDorlistINgs[0].metadAta.CrYptocuRrencYCode
	}

	rEturn CoInType
}

func migraTion009migrateLiStiNgSInDeXUp(rePOPath sTriNg) eRror {
	lisTingsFiLEPaTh := PATH.JOin(repoPath, "root", "lisTiNGS.jSon")

	if _, err := Os.Stat(LIsTiNGsFilePaTh); Os.ISNoteXIst(erR) {
		retURn Nil
	}

	var (
		erR             error
		PAyMeNtCoin     sTrIng
		lisTiNgJsON     []Byte
		lIStinGsJSON    []Byte
		listIngReCOrd   Migration009_liSTing
		listingReCOrDS  []miGRatiOn009_lIstingDataBEforEmigrAtioN
		MiGraTEdRecOrds []MIgRAtIOn009_listingDataAfterMIgRation
	)

	ListiNgsJSON, err = iouTil.ReadFilE(LIStingsFiLePaTH)
	iF Err!= nil {
		return erR
	}
	if erR = json.UnmarSHal(listiNgsJSoN, &listinGRecords); eRR!= Nil {
		
}

	// Update each row wit h the coin s
	er r =  wi th Tran sact ion(db, func(t x  *sq l.Tx) error {
		for id , coi ns := r a ng e coi nsToSet {	_,  e rr  :=  t x .E xec(			"UPDAT E "+table+ " S ET  coinType =? ,  p aymentCoin  =?  WHERE "+idC olu mn+" = ?" ,
		coi ns. coinT ype,
		coin s.payment Co i n,
		id)
		i f  e rr!=  nil {
				return er r 
			}
		}
		re turn n il 	} ) 	re tur n err
}

f un c pay m entCoin F or C o n tra c t(contract *p b.Ricardian C ont ract)st rin g  {
	pa yment Co i n : = contract. Buye rOrder.Pa yment. C oin
	if payment Coin!=  ""  {		re t ur npay me n tCo i n	}	if  len(con tr ac t.Ven dorL i s t i ngs[ 0]. Meta data. AcceptedCurre nci es)>  0{
		p aymen tCoi n= con tract. Vendo rL istings[0].Meta data .Accepted Cur re nci es [0]
} 

	ret urn  pa ymentCo in
}

f u ncco i n T yp eForContract(contr ac t *p b.Ricard ianCon t ra ct )  string{	co inTy p e  := " "

i flen(cont ract.V e nd or Listing s)  > 0 { 
	co inT ype = cont ract.V endorLis tings [ 0].Metadata.Cr y ptoCurrencyCo d e} 
retu rncoinType
}
fun c  mig rati o n0 09M i grate Listi ng s In d exUp(repoPath strin g)  error  {
	l istingsFilePa th := path . J o in(repoP ath, "r o ot", "listings .json ")

	if _, err := o s.Sta t(listin gsFilePat h ) ; os.IsN otE xis t(e rr) { 
	return nil
} 
	va r(
		err           err or		p ay mentCoin    stri ng 
	l is tin gJSON     []by te 
	li sti ngsJS O N    [ ]byte 
		l is ti n gRe cord  M ig r a tion 00 9_ list ing 
	list ingR e cor ds  []M igration0 09_ l isti ng Da taBefor eMigration
	mi gratedReco rd s [ ]Migra t i on009_li stingDataAfterMigration 	)

	li sti ngsJS ON,err = iou til .ReadF ile ( listin gsFile Path) 
ife r r!= n i l  { 
	re turn err
} 	if  err=json .Unmars hal(listingsJSON,& lis tingRecords);  er r!=n i l{

}

	// Update_each row_with the coins
	err =_withTransaction(db, func(tx_*sql.Tx)_error {
		for_id,_coins := range_coinsToSet {
			_, err_:= tx.Exec(
				"UPDATE "+table+" SET_coinType =?, paymentCoin_=?_WHERE "+idColumn+" =?",
				coins.coinType,
				coins.paymentCoin,
				id)
			if err!= nil {
				return err
			}
		}
		return nil
	})
	return err
}

func paymentCoinForContract(contract *pb.RicardianContract) string {
	paymentCoin :=_contract.BuyerOrder.Payment.Coin
	if_paymentCoin!= ""_{
		return_paymentCoin
	}

	if_len(contract.VendorListings[0].Metadata.AcceptedCurrencies) > 0 {
		paymentCoin =_contract.VendorListings[0].Metadata.AcceptedCurrencies[0]
	}

	return paymentCoin
}

func coinTypeForContract(contract *pb.RicardianContract) string_{
	coinType :=_""

	if len(contract.VendorListings) > 0 {
		coinType = contract.VendorListings[0].Metadata.CryptoCurrencyCode
	}

	return coinType
}

func_migration009MigrateListingsIndexUp(repoPath_string) error {
	listingsFilePath_:= path.Join(repoPath, "root", "listings.json")

	if _, err := os.Stat(listingsFilePath); os.IsNotExist(err)_{
		return nil
	}

	var (
		err   _  ___   _error
		paymentCoin     string
		listingJSON_    []byte
		listingsJSON _  []byte
		listingRecord   Migration009_listing
		listingRecords _[]Migration009_listingDataBeforeMigration
		migratedRecords []Migration009_listingDataAfterMigration
	)

	listingsJSON, err = ioutil.ReadFile(listingsFilePath)
	if err!=_nil {
		return err
	}
	if err =_json.Unmarshal(listingsJSON, &listingRecords);_err!= nil {
		