~singpolyma/sgx-jmp

d799a928330b0a8709084e8ea6a431979949a37e — Stephen Paul Weber 1 year, 1 month ago 71349ef
Ask electrum to notify on new BTC addresses

Otherwise we won't know when someone has paid...
5 files changed, 19 insertions(+), 2 deletions(-)

M config.dhall.sample
M lib/customer.rb
M lib/electrum.rb
M test/test_customer.rb
M test/test_helper.rb
M config.dhall.sample => config.dhall.sample +2 -0
@@ 66,6 66,8 @@
	activation_amount = 15,
	credit_card_url = \(jid: Text) -> \(customer_id: Text) ->
		"https://pay.jmp.chat/${jid}/credit_cards?customer_id=${customer_id}",
	electrum_notify_url = \(address: Text) -> \(customer_id: Text) ->
		"https://pay.jmp.chat/electrum_notify?address=${address}&customer_id=${customer_id}",
	adr = "",
	interac = "",
	payable = ""

M lib/customer.rb => lib/customer.rb +4 -1
@@ 91,7 91,10 @@ class Customer
		REDIS.spopsadd([
			"jmp_available_btc_addresses",
			"jmp_customer_btc_addresses-#{customer_id}"
		])
		]).then do |addr|
			ELECTRUM.notify(addr, CONFIG[:electrum_notify_url].call(addr, customer_id))
			addr
		end
	end

	protected def_delegator :@plan, :expires_at

M lib/electrum.rb => lib/electrum.rb +4 -0
@@ 34,6 34,10 @@ class Electrum
		rpc_call(:get_tx_status, txid: tx_hash).then { |r| r["result"] }
	end

	def notify(address, url)
		rpc_call(:notify, address: address, URL: url).then { |r| r["result"] }
	end

	class Transaction
		def initialize(electrum, tx_hash, tx)
			@electrum = electrum

M test/test_customer.rb => test/test_customer.rb +7 -0
@@ 5,6 5,7 @@ require "customer"

Customer::BLATHER = Minitest::Mock.new
Customer::BRAINTREE = Minitest::Mock.new
Customer::ELECTRUM = Minitest::Mock.new
Customer::REDIS = Minitest::Mock.new
Customer::DB = Minitest::Mock.new
CustomerPlan::DB = Minitest::Mock.new


@@ 239,8 240,14 @@ class CustomerTest < Minitest::Test
			EMPromise.resolve("testaddr"),
			[["jmp_available_btc_addresses", "jmp_customer_btc_addresses-test"]]
		)
		Customer::ELECTRUM.expect(
			:notify,
			EMPromise.resolve(nil),
			["testaddr", "http://notify.example.com"]
		)
		assert_equal "testaddr", Customer.new("test").add_btc_address.sync
		assert_mock Customer::REDIS
		assert_mock Customer::ELECTRUM
	end
	em :test_add_btc_address
end

M test/test_helper.rb => test/test_helper.rb +2 -1
@@ 74,7 74,8 @@ CONFIG = {
			USD: "merchant_usd"
		}
	},
	credit_card_url: ->(*) { "http://creditcard.example.com" }
	credit_card_url: ->(*) { "http://creditcard.example.com" },
	electrum_notify_url: ->(*) { "http://notify.example.com" }
}.freeze

BLATHER = Class.new {