forked from Abhi5415/auxilium
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/Abhi5415/auxilium into HEAD
- Loading branch information
Showing
4 changed files
with
96 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,69 @@ | ||
const StellarSdk = require("stellar-sdk"); | ||
const StellarSdk = require('stellar-sdk'); | ||
StellarSdk.Network.useTestNetwork(); | ||
const server = new StellarSdk.Server("https://horizon-testnet.stellar.org"); | ||
const validate = require("jsonschema").validate; | ||
const server = new StellarSdk.Server('https://horizon-testnet.stellar.org'); | ||
const validate = require('jsonschema').validate; | ||
|
||
const publicKey = "GAI6C5X6QK5KE3OXXIQAUZ33WCMCENCJ5VDYRKNZCR6LCYRM5PSQGFOG"; | ||
const secretString = "SALEHVAPOGW677KLEDFNQZ3WA7JSQCN2UJ37CUXHZOXIKHPEOOV264L7"; | ||
const publicKey = 'GAI6C5X6QK5KE3OXXIQAUZ33WCMCENCJ5VDYRKNZCR6LCYRM5PSQGFOG'; | ||
const secretString = 'SALEHVAPOGW677KLEDFNQZ3WA7JSQCN2UJ37CUXHZOXIKHPEOOV264L7'; | ||
|
||
// let transactionExample = { | ||
// u: "41614", | ||
// a: -1234 | ||
// }; | ||
|
||
exports.submitTransaction = async payload => { | ||
try { | ||
const account = await server.loadAccount(publicKey); | ||
const fee = await server.fetchBaseFee(); | ||
const memo = new StellarSdk.Memo.text(JSON.stringify(payload)); | ||
try { | ||
const account = await server.loadAccount(publicKey); | ||
const fee = await server.fetchBaseFee(); | ||
const memo = new StellarSdk.Memo.text(JSON.stringify(payload)); | ||
|
||
const transaction = new StellarSdk.TransactionBuilder(account, { | ||
fee, | ||
memo | ||
}) | ||
.addOperation( | ||
StellarSdk.Operation.payment({ | ||
destination: publicKey, | ||
asset: StellarSdk.Asset.native(), | ||
amount: "0.0000001" | ||
}) | ||
) | ||
.setTimeout(30) | ||
.build(); | ||
const transaction = new StellarSdk.TransactionBuilder(account, { | ||
fee, | ||
memo, | ||
}) | ||
.addOperation( | ||
StellarSdk.Operation.payment({ | ||
destination: publicKey, | ||
asset: StellarSdk.Asset.native(), | ||
amount: '0.0000001', | ||
}) | ||
) | ||
.setTimeout(30) | ||
.build(); | ||
|
||
transaction.sign(StellarSdk.Keypair.fromSecret(secretString)); | ||
transaction.sign(StellarSdk.Keypair.fromSecret(secretString)); | ||
|
||
const transactionResult = await server.submitTransaction(transaction); | ||
const transactionResult = await server.submitTransaction(transaction); | ||
|
||
console.log(transactionResult); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
console.log(transactionResult); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}; | ||
|
||
exports.getTransactions = async () => { | ||
let history = []; | ||
let history = []; | ||
|
||
r = await server | ||
.transactions() | ||
.limit(1) | ||
.forAccount(publicKey) | ||
.call(); | ||
while (r.records.length != 0) { | ||
let record = r.records[0]; | ||
r = await server | ||
.transactions() | ||
.limit(1) | ||
.forAccount(publicKey) | ||
.call(); | ||
while (r.records.length != 0) { | ||
let record = r.records[0]; | ||
|
||
if ( | ||
record.hasOwnProperty("memo") && | ||
validate(record, { type: "object" }).errors.length == 0 | ||
) { | ||
let parsedRecord = JSON.parse(record.memo); | ||
parsedRecord.r = record._links.self.href; | ||
history.push(parsedRecord); | ||
} | ||
if ( | ||
record.hasOwnProperty('memo') && | ||
validate(record, { type: 'object' }).errors.length == 0 | ||
) { | ||
let parsedRecord = JSON.parse(record.memo); | ||
parsedRecord.r = record._links.self.href; | ||
history.push(parsedRecord); | ||
} | ||
|
||
r = await r.next(); | ||
} | ||
return history; | ||
r = await r.next(); | ||
} | ||
return history; | ||
}; | ||
|
||
exports.getTransactions(); |