Blocktrail Bitcoin API receive payment - payment

After I created an address, a webhook (on that address [address-transactions]), and sent BTC to that address, I am getting a callback.
How can I get the address, which was the purpose of payment (receive address)?
How can I be sure?
Callback below:
{"network":"tBTC","event_type":"address-transactions","data":{"raw":"010000000106b42c1327a982269aba7fe648efd85af636f95929bf9c7753db1874989ddfca00000000fdfd0000483045022100b244d43adb41687aa1382a8839e5ed71ead23b85e0080f19eb00842bfddf183b022052c48e9345a060224b6b73066556b1e7af8e6304e9aab4b580477ec6b5ea50d501473044022065b019ba879a361082990e466c74adce23dbe04f73bf5f8b24e68740a39779c6022023d3e0170a420032d25e84c02d4c37f14f83f644ef46f3d3fc71aa86cc937da8014c69522102e395f291278488ba971b94ce7ddef42020c351e7e6066ae0d031215fdaa20a6521035966e7947541ccd494bef89f2035bdddb9ecd74c7865fa5180acbeefedc151e62103820f089836a6a19d1a1c3a9e4a1d6532d2721ffad373fcf8093926c01097945253aeffffffff02801a06000000000017a91402994d31fb6c69f0a0399b879a7713130c75b894877ee43d000000000017a914415e211a35874aad3561c72f79d36655bf1829fa8700000000","hash":"f7e57a938f1e1cb0edf3f32d3af1aeb5d97b6fed2cbcd13f72f31e3c49f9c299","first_seen_at":"2016-06-13T19:15:45+0000","last_seen_at":"2016-06-13T19:15:45+0000","block_height":870128,"block_time":"2016-06-13T20:41:54+0000","block_hash":"00000000002fc98e5a4b655daef4d609ecc64f3f4bd74220cc516e83e2359d30","confirmations":1,"is_coinbase":false,"estimated_value":400000,"total_input_value":4460000,"total_output_value":4456190,"total_fee":3810,"estimated_change":4056190,"estimated_change_address":"2MyCrfyKKb7LMsx5F4mmDVbwQSfEMspaopx","high_priority":false,"enough_fee":false,"contains_dust":false,"inputs":[{"index":0,"output_hash":"cadf9d987418db53779cbf2959f936f65ad8ef48e67fba9a2682a927132cb406","output_index":0,"value":4460000,"address":"2N4ufH2284xz1BEFnpi4rU2KZk9YUmtzTtT","type":"scripthash","multisig":null,"multisig_addresses":null,"script_signature":"00483045022100b244d43adb41687aa1382a8839e5ed71ead23b85e0080f19eb00842bfddf183b022052c48e9345a060224b6b73066556b1e7af8e6304e9aab4b580477ec6b5ea50d501473044022065b019ba879a361082990e466c74adce23dbe04f73bf5f8b24e68740a39779c6022023d3e0170a420032d25e84c02d4c37f14f83f644ef46f3d3fc71aa86cc937da8014c69522102e395f291278488ba971b94ce7ddef42020c351e7e6066ae0d031215fdaa20a6521035966e7947541ccd494bef89f2035bdddb9ecd74c7865fa5180acbeefedc151e62103820f089836a6a19d1a1c3a9e4a1d6532d2721ffad373fcf8093926c01097945253ae"}],"outputs":[{"index":0,"value":400000,"address":"2MsUxzFCWuiJJSouCHko2BkV9u3Md5q9D8T","type":"scripthash","multisig":null,"multisig_addresses":null,"script":"OP_HASH160
02994d31fb6c69f0a0399b879a7713130c75b894
OP_EQUAL","script_hex":"a91402994d31fb6c69f0a0399b879a7713130c75b89487","spent_hash":null,"spent_index":0},{"index":1,"value":4056190,"address":"2MyCrfyKKb7LMsx5F4mmDVbwQSfEMspaopx","type":"scripthash","multisig":null,"multisig_addresses":null,"script":"OP_HASH160
415e211a35874aad3561c72f79d36655bf1829fa
OP_EQUAL","script_hex":"a914415e211a35874aad3561c72f79d36655bf1829fa87","spent_hash":null,"spent_index":0}]},"retry_count":"6","addresses":{"2N4ufH2284xz1BEFnpi4rU2KZk9YUmtzTtT":-4460000}}
Thank you very much for your help.

The addresses portion in the last line (in your example) has the address. It is a key so you can use .keys() and select the first one. Here is an example of how I parsed it using python:
data = json.loads(request.body)
address = data['addresses'].keys()[0]
amount = data['addresses'][address]
confirmations = data['data']['confirmations']

Related

Binance Smart Chain safeTransferFrom function with transfer comments not working

I have successfully deployed and verified an ERC721 smart contract on BSC's testnet. Also successfully minted and awarded new ERC721 tokens. Next up is transferring tokens between wallets. So far so good, except that I'd like to add transfer comments to the transfer transactions.
My contract supports the standard safeTransferFrom(senderWaller, receiverWallet, tokenId, data) function, and I can see the data (i.e. - the transfer comment) being sent out. But it doesn't appear when I view the successful transaction in the BSC testnet explorer.
Here is an example transaction --> https://testnet.bscscan.com/tx/0x1f3bf69da66cff66bbeeb6ce6f7505be8a78729685162811cb29c9dc30a347d6. Decoding the data in the BSC testnet explorer I can see the trailing data in hex form and it translates back to readable text when I convert it back. See trailing value starting with 205363... below. Here is a screen shot of the hex converting back to the intended text value.
Function: safeTransferFrom(address from, address to, uint256 tokenId, bytes _data)
MethodID: 0xb88d4fde
[0]: 0000000000000000000000008175f3b00af0b775136b918a78298aaf4e1ea137
[1]: 000000000000000000000000ba3662af7c0cecd20cd97ef8072c30f4449b16b1
[2]: 0000000000000000000000000000000000000000000000000000000000000005
[3]: 0000000000000000000000000000000000000000000000000000000000000080
[4]: 0000000000000000000000000000000000000000000000000000000000000020
[5]: 5363686564756c656420736572766963696e6700000000000000000000000000
Here is my code that is used to encode the web3 method call.
const soygaToken = new web3.eth.Contract(soygaABI, contractAddress);
var byteComments = Buffer.from(comments.padEnd(32, "\0"), 'utf-8');
var myData = soygaToken.methods.safeTransferFrom(senderAddress, recipientAddress, tokenId, byteComments).encodeABI();
Any ideas as to what's causing this data to be missing from the transaction when I look on the BSC testnet explorer? Reviewing the ERC721 specs (https://ethereum.org/en/developers/docs/standards/tokens/erc-721/) the data parameter should be a 32-byte value. Which it appears I'm passing along.
Bounced this off the core Nethereum developer. He verified the user data is present, but it's likely just an issue where the Etherscan web client isn't decoding it. So the user data should be accessible.

Let Alexa ask the user a follow up question (NodeJS)

Background
I have an Intent that fetches some Data from an API. This data contains an array and I am iterating over the first 10 entries of said array and read the results back to the user. However the Array is almost always bigger than 10 entries. I am using Lambda for my backend and NodeJS as my language.
Note that I am just starting out on Alexa and this is my first skill.
What I want to archive is the following
When the user triggers the intent and the first 10 entries have been read to the user Alexa should ask "Do you want to hear the next 10 entries?" or something similar. The user should be able to reply with either yes or no. Then it should read the next entries aka. access the array again.
I am struggling with the Alexa implementation of this dialog.
What I have tried so far: I've stumbled across this post here, however I couldn't get it to work and I didn't find any other examples.
Any help or further pointers are appreciated.
That tutorial gets the concept right, but glosses over a few things.
1: Add the yes and no intents to your model. They're "built in" intents, but you have to add them to the model (and rebuild it).
2: Add your new intent handlers to the list in the .addRequestHandlers(...) function call near the bottom of the base skill template. This is often forgotten and is not mentioned in the tutorial.
3: Use const sessionAttributes = handlerInput.attributesManager.getSessionAttributes(); to get your stored session attributes object and assign it to a variable. Make changes to that object's properties, then save it with handlerInput.attributesManager.setSessionAttributes(sessionAttributes);
You can add any valid property name and the values can be a string, number, boolean, or object literal.
So assume your launch handler greets the customer and immediately reads the first 10 items, then asks if they'd like to hear 10 more. You might store sessionAttributes.num_heard = 10.
Both the YesIntent and LaunchIntent handlers should simply pass a num_heard value to a function that retrieves the next 10 items and feeds it back as a string for Alexa to speak.
You just increment sessionAttributes.num_heard by 10 each time that yes intent runs and then save it with handlerInput.attributesManager.setSessionAttributes(sessionAttributes).
What you need to do is something called "Paging".
Let's imagine that you have a stock of data. each page contains 10 entries.
page 1: 1-10, page 2: 11-20, page 3: 21-30 and so on.
When you fetching your data from DB you can set your limitations, In SQL it's implemented with LIMIT ,. But how you get those values based on the page index?
Well, a simple calculation can help you:
let page = 1 //Your identifier or page index. Managed by your client frontend.
let chunk = 10
let _start = page * chunk - (chunk - 1)
let _end = start + (chunk - 1)
Hope this helped you :)

Stripe: Getting Credit Card's Last 4 Digits

I have upgraded the Stripe.net to the latest version which is 20.3.0 and now I don't seem to find the .Last4 for the credit card. I had the following method:
public void CreateLocalCustomer(Stripe.Customer stipeCustomer)
{
var newCustomer = new Data.Models.Customer
{
Email = stipeCustomer.Email,
StripeCustomerId = stipeCustomer.Id,
CardLast4 = stipeCustomer.Sources.Data[0].Card.Last4
};
_dbService.Add(newCustomer);
_dbService.Save();
}
But now the stipeCustomer.Sources.Data[0].Card.Last4 says 'IPaymentSource' does not contain a definition for 'Card'. Does anyone know how I can get the card details now? The flow is that I create the customer by passing the Stripe token to Stripe, then I get the above stripeCustomer. So I expect it to be somewhere in that object. But I can't find it. The release notes can be found here.
Thank you.
In the old world of Stripe, there only used to be one type of payment method you could attach to a Customer; specifically, Card-objects. You would create a Card-object by using Stripe.js/v2 or the Create Token API Endpoint to first create a Token-object and then attach that token to a Customer-object with the Create Card API Endpoint.
Once Stripe expanded to support a number of other payment methods though, Stripe built support for a new object type that encapsulated a number of payment methods (including credit cards) called Source-objects. A Source-object is created either by using Stripe.js/v3 or the Create Source API Endpoint. It can also be attached to a Customer-object in much the same way as the Card-objects mentioned above, except they retain their object type. They're still a Source. You use the Attach Source API Endpoint to do this (that is notably identical to the Create Card API Endpoint mentioned above).
What I'm getting at here, is there are now two different object types (or more) that you can expect to see returned in the sources-array (or Sources in .NET). All of these methods though inherit from the IPaymentSource-interface. So if you know you have a Card-object getting returned, you can simply cast the returned object to the Card-class.
Something like this should get you going:
CardLast4 = ((Card) stipeCustomer.Sources.Data[0]).Last4
You can see what I mean by inheritance by looking at this line in the Card-class file:
https://github.com/stripe/stripe-dotnet/blob/master/src/Stripe.net/Entities/Cards/Card.cs#L7
Good luck!
As of Stripe.net.21.4.1, this is what works:
var chargeService = new ChargeService();
var charge = chargeService.Get(id);
CardLast4 = ((Card)charge.Source).Last4;
It's getting hard not to panic when code breaks because of all the micro-changes Stripe makes.
So after debugging, it looks like the Data[0] needs to be cast as Card to get the card.
So it will be CardLast4 = ((Card)stipeCustomer.Sources.Data[0]).Last4.

how to set the From field in an email

If I send an email from javascript, the email arrives at the destination address with the "From" field containing Anonymous%<Notes domain>#Company.com. I tried setting the fields "reply-to", "return-path", "From", "Sender", & "Principal" with what I want to appear in the "From" field.
But that often results in a bounce-back message because, I believe, it looks like the "From" address is being spoofed (which is actually is but for a good cause!). How can I modify the "From" field?
Here's the code using mail.box that's throwing the error:
function sendTestEmail(emailAddr){
print("enter sendTestEmail function");
print("emailAddr: "+emailAddr);
var mailboxdb:NotesDatabase = sessionAsSigner.getDatabase("<server>", "mail.box");
var emaildoc:NotesDocument = mailboxdb.createDocument();
emaildoc.replaceItemValue("form", "Memo");
emaildoc.replaceItemValue("sendTo", emailAddr);
emaildoc.replaceItemValue("subject", "testing email");
var body:NotesRichTextItem = emaildoc.createRichTextItem("body");
body.addNewLine();
body.appendText(" testing from javascript. ");
emaildoc.replaceItemValue("SMTPOriginator", "support#abc.com");
emaildoc.replaceItemValue("From","\"support#abc.com\" <support#abc.com>");
emaildoc.replaceItemValue("Principal","\"support#abc.com\" <support#abc.com>");
emaildoc.save(true, false);
print("exiting sendTestEmail function");
}
Copy the mail into server's database mail.box instead of sending it and set fields "Principal" and "From" to your alternative address.
Have a look at this answer too.
Set the SMTPOriginator field to the address it should be from. You might still need to populate the From, Sender and Principal as well.
Just another idea, because to me the mail.box idea should be a last resort approach.
If the mail is always to be sent by the same person (e.g. support), you could prepare a draft mail somewhere, for instance in your current database, and have a signed, scheduled agent (LS, Java) that sends the mails out.
I once used a special Extension Manager DLL to rename certain fields in outgoing mails, but I'm not going to propose that idea here...

Error in checking an email id is valid using Mail::CheckUser

I am creating a script for checking mail id inbox exist or not (mail probing), i am using Mail::CheckUser module for this.But when i execute the code with a mail id like "somthing#yahooo.com" it shows the mail id exist ,but it does not exist in reality.
could you please suggest any solution for this
the code i am usig is given below
use Mail::CheckUser;
use Data::Dumper;
my $res =Mail::CheckUser::check_email('something_something#yahoo.com');
print $res."\n\n\n";
my $res1 = Mail::CheckUser::last_check();
print Dumper($res1)."\n\n";
thanks in advance
Mail::Checker seems to be unfit for Yahoo
It seems that it is impossible to test existence of yahoo mailbox without sending a test message. Yahoo seems to reject messages to non existing user in reply to "the final dot" in SMTP session.
I have tried to send message to non existing (long random) mailbox with the following result (bounce message):
<d5b980c9018f82c94cefee51193f8a61#yahoo.com>: host
mta5.am0.yahoodns.net[98.138.112.32] said: 554 delivery error: dd This user
doesn't have a yahoo.com account
(d5b980c9018f82c94cefee51193f8a61#yahoo.com) [0] -
mta1516.mail.ne1.yahoo.com (in reply to end of DATA command)

Resources