Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow trust after creating a trustline. #9

merged 1 commit into from Jul 9, 2018
Show file tree
Hide file tree
Changes from all commits
File filter

Filter by extension

Filter by extension

Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/index.ts
Expand Up @@ -3,6 +3,7 @@ import { importSchema } from 'graphql-import'
import { Prisma } from './generated/prisma'
import {
} from './utils'
Expand Down Expand Up @@ -60,9 +61,9 @@ const resolvers = {
app. Use something like AWS lambda, or a separate system to
provision the Stellar account.

await createAccountInLedger(keypair.publicKey())
await createTrustline(keypair)
await allowTrust(keypair.publicKey())

return user
Expand Down
34 changes: 32 additions & 2 deletions src/utils.ts
Expand Up @@ -26,8 +26,6 @@ export async function createAccountInLedger(newAccount) {

// Never put values like the an account seed in code.
const provisionerKeyPair = Keypair.fromSecret('SA72TGXRHE26WC5G5MTNURFUFBHZHTIQKF5AQWRXJMJGZUF4XY6HFWJ4')
const issuerKeyPair = Keypair.fromSecret('SBYZ5NEJ34Y3FTKADVBO3Y76U6VLTREJSW4MXYCVMUBTL2K3V4Y644UX')

const provisioner = await stellarServer.loadAccount(provisionerKeyPair.publicKey())

console.log('creating account in ledger', newAccount)
Expand Down Expand Up @@ -73,3 +71,35 @@ export async function createTrustline(accountKeypair) {
console.log('create trustline failed.', e)

export async function allowTrust(trustor) {
const stellarServer = new Server('');

try {
// Never store secrets in code! Use something like KMS and put
// this somewhere were few people can access it.
const issuingKeys = Keypair.fromSecret('SBYZ5NEJ34Y3FTKADVBO3Y76U6VLTREJSW4MXYCVMUBTL2K3V4Y644UX')
const issuingAccount = await stellarServer.loadAccount(issuingKeys.publicKey())

const transaction = new TransactionBuilder(issuingAccount)
assetCode: AnchorXUSD.code,
authorize: true


const result = await stellarServer.submitTransaction(transaction)

console.log('trust allowed', result)

return result
} catch (e) {
console.log('allow trust failed', e)