Skip to content

Instantly share code, notes, and snippets.

class Bitcoins::Index < BrowserAction
get "/bitcoins" do
addresses = KeyPairQuery.new.user_id(current_user.id).map { |key_pair|
{ key_pair.label, key_pair.public_key, "0" }
}
render IndexPage, addresses: addresses
end
end
class KeyPairQuery < KeyPair::BaseQuery
end
@9876691
9876691 / index.cr
Last active September 7, 2018 13:50
class Bitcoins::Index < BrowserAction
get "/bitcoins" do
addresses = Array(Tuple(String, String, String)).new
render IndexPage, addresses: addresses, form: KeyPairForm.new
end
end
@9876691
9876691 / create.cr
Last active September 7, 2018 13:39
class Bitcoins::Create < BrowserAction
route do
KeyPairForm.create(params, user_id: current_user.id) do |form, key_pair|
if key_pair
flash.info = "Bitcoin address successfully generated"
redirect to: Bitcoins::Index
else
flash.danger = "Unable to generate Bitcoin Address, Please try again."
addresses = KeyPairQuery.new.user_id(current_user.id).map{ |keypair|
class Bitcoins::IndexPage < MainLayout
needs addresses : Array(Tuple(String, String, String))
needs form : KeyPairForm
def content
render_key_pair_form(@form)
h1 "Your Bitcoin Addresses"
class KeyPairForm < KeyPair::BaseForm
fillable label
fillable public_key
fillable private_key
end
require "./user"
class KeyPair < BaseModel
table :key_pairs do
column label : String
column public_key : String
column private_key : String
belongs_to user : User
end
end
import Bitcoin from "bitcoinjs-lib"
const testnet = Bitcoin.networks.testnet
const keyPair = Bitcoin.ECPair.makeRandom({ network: testnet })
console.log(Bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey, network: testnet }).address)
@9876691
9876691 / create.cr
Last active September 7, 2018 14:11
Redirection using type safe URL's.
Authentic.redirect_to_originally_requested_path(self, fallback: Bitcoins::Index)
class Bitcoins::IndexPage < MainLayout
needs addresses : Array(Tuple(String, String, String))
def content
h1 "Your Bitcoin Addresses"
table class: "table" do
thead do