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
merged 1 commit into from Jul 9, 2018
File filter...
Filter file types
Jump to file or symbol
Failed to load files and symbols.
+34 −3
Diff settings

Always

Just for now

Copy path View file
@@ -3,6 +3,7 @@ import { importSchema } from 'graphql-import'
import { Prisma } from './generated/prisma'
import {
Context,
allowTrust,
createAccountInLedger,
createTrustline
} from './utils'
@@ -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
},
Copy path View file
@@ -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)
@@ -73,3 +71,35 @@ export async function createTrustline(accountKeypair) {
console.log('create trustline failed.', e)
}
}

export async function allowTrust(trustor) {
Network.useTestNetwork();
const stellarServer = new Server('https://horizon-testnet.stellar.org');

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)
.addOperation(
Operation.allowTrust({
trustor,
assetCode: AnchorXUSD.code,
authorize: true
})
)
.build();

transaction.sign(issuingKeys);

const result = await stellarServer.submitTransaction(transaction)

console.log('trust allowed', result)

return result
} catch (e) {
console.log('allow trust failed', e)
}
}
ProTip! Use n and p to navigate between commits in a pull request.