2017-06-15 19:16:45 +02:00
|
|
|
//=include bigchain/smoothscroll.js
|
2017-04-12 15:42:35 +02:00
|
|
|
//=include bigchain/newsletter.js
|
2016-02-10 01:04:57 +01:00
|
|
|
|
|
|
|
jQuery(function($) {
|
|
|
|
|
2017-06-15 19:16:45 +02:00
|
|
|
//
|
|
|
|
// init modules
|
|
|
|
//
|
2017-04-12 15:42:35 +02:00
|
|
|
Newsletter.init()
|
2017-06-15 19:16:45 +02:00
|
|
|
})
|
2017-06-22 17:03:05 +02:00
|
|
|
|
2017-06-22 17:23:48 +02:00
|
|
|
//=include bigchaindb-driver/dist/browser/bundle.window.min.js
|
|
|
|
|
|
|
|
window.addEventListener('DOMContentLoaded', function domload(event){
|
|
|
|
window.removeEventListener('DOMContentLoaded', domload, false)
|
2017-06-22 17:03:05 +02:00
|
|
|
|
|
|
|
const driver = window.BigchainDB
|
|
|
|
const API_PATH = 'https://test.ipdb.io/api/v1/'
|
|
|
|
const APP_ID = 'b563bf22'
|
|
|
|
const APP_KEY = 'fd639614dcf8ee90a8c51a013ac11fb0'
|
|
|
|
|
2017-06-22 17:23:48 +02:00
|
|
|
const form = document.getElementById('form-transaction')
|
2017-06-22 17:03:05 +02:00
|
|
|
const postButton = document.getElementById('post')
|
|
|
|
|
|
|
|
postButton.addEventListener('click', function(e) {
|
|
|
|
e.preventDefault()
|
|
|
|
|
|
|
|
const message = document.getElementById('message').value
|
|
|
|
|
2017-06-22 17:23:48 +02:00
|
|
|
const alice = new driver.Ed25519Keypair()
|
2017-06-22 17:03:05 +02:00
|
|
|
const tx = driver.Transaction.makeCreateTransaction(
|
|
|
|
{ assetMessage: message },
|
2017-06-22 17:39:36 +02:00
|
|
|
{ metaDataMessage: 'hello' },
|
2017-06-22 17:03:05 +02:00
|
|
|
[ driver.Transaction.makeOutput(
|
|
|
|
driver.Transaction.makeEd25519Condition(alice.publicKey))
|
|
|
|
],
|
|
|
|
alice.publicKey
|
|
|
|
)
|
|
|
|
const txSigned = driver.Transaction.signTransaction(tx, alice.privateKey)
|
|
|
|
|
|
|
|
const conn = new driver.Connection(API_PATH, {
|
|
|
|
app_id: APP_ID,
|
|
|
|
app_key: APP_KEY
|
|
|
|
})
|
|
|
|
|
2017-06-22 18:12:56 +02:00
|
|
|
const waiting = document.getElementsByClassName('waiting')[0]
|
|
|
|
const response = document.getElementsByClassName('response')[0]
|
|
|
|
const output = document.getElementsByClassName('output')[0]
|
2017-06-22 18:23:47 +02:00
|
|
|
const messageSuccess = document.getElementsByClassName('message--success')[0]
|
|
|
|
const messageFail = document.getElementsByClassName('message--fail')[0]
|
2017-06-22 18:12:56 +02:00
|
|
|
|
2017-06-22 17:03:05 +02:00
|
|
|
conn.postTransaction(txSigned)
|
|
|
|
.then(() => {
|
2017-06-22 18:12:56 +02:00
|
|
|
waiting.classList.add('hide')
|
|
|
|
response.classList.remove('hide')
|
|
|
|
|
2017-06-22 17:03:05 +02:00
|
|
|
const outputContent = conn.getStatus(txSigned.id)
|
2017-06-22 18:12:56 +02:00
|
|
|
output.textContent = outputContent
|
|
|
|
}, reason => { // Error!
|
|
|
|
console.log(reason)
|
|
|
|
|
|
|
|
waiting.classList.add('hide')
|
|
|
|
response.classList.remove('hide')
|
2017-06-22 18:23:47 +02:00
|
|
|
messageFail.classList.remove('hide')
|
2017-06-22 17:03:05 +02:00
|
|
|
|
2017-06-22 18:12:56 +02:00
|
|
|
const outputContent = reason.status + ' ' + reason.statusText
|
2017-06-22 17:03:05 +02:00
|
|
|
output.textContent = outputContent
|
|
|
|
})
|
|
|
|
.then((res) => console.log('Transaction status:', res.status))
|
|
|
|
|
|
|
|
}, false)
|
|
|
|
}, false)
|