I'm using the bloomberg api to code a cpp project.
When I need to send a request to the Bloomberg data feed, I must send the request with an ID. For example:
session->sendRequest(*request, CorrelationId(20));
The CorrelationId is provided by the bloomberg api to generate an ID.
The ID here is 20. The result coming from the bloomberg data feed contains the ID 20 so that I can identity the result and the request. Meaning that when I get the result from the data feed, there is something like this:
correlationId=[ valueType=INT classId=0 value=20 ]
Now I want to make a string ID, instead of the int ID. For example, I want to generate an ID like CorrelationId("US543119ES").
If I do this, I get no error but the ID in the result becomes:
correlationId=[ valueType=POINTER classId=0 value=00731378 ]
It seems that the ID becomes a pointer and it sends the value of the pointer, instead of the content of the pointer. Obviously value=00731378 is an address.
Is it impossible to generate a string ID?
If possible, what should I do?
I've found the documentation of CorrelationId.
There are two constructors of CorrelationId that I don't know how to use, I don't know if one of them is what I need:
CorrelationId (void *value, int classId=0);
template<typename TYPE >
CorrelationId (const TYPE &smartPtr, void *pointerValue, int classId=0);
If we want to generate a string ID, we can just send the address of the string. Then the bloomberg data feed will send us back the address, whose type is void *. So we just need to convert it into char *. Here is an example:
// sending
const char * id = "abc";
session->sendRequest(*request, CorrelationId(const_cast<char *>(id))); // it can't take "const char *"
// handling response
cout << (char *)message.correlationId().asPointer(); // it will show "abc".
Related
I have to sign a raw transaction on testnet whose hex is given below, I tried hard coding everything in transaction generate part, it is broadcasting properly.
but I have to implement the transaction and signature part separately.
I am using bitcore-lib-cash package
const bitcore = require('bitcore-lib-cash')
const txhex = 010000000139a7e6578a862a10151bdbe0ed4a833cd615273b0cd0ecda1616ee8407d7d8040000000000ffffffff0241010000000000001976a914f0ac6825bd05b406d5224eab0be73852a487e06c88ac94dc0100000000001976a914185ec62d62510d40795109e6484e0487c28a3caf88ac00000000
const private_key = 'private key here'
let transaction = new bitcore.Transaction(txbuffer).sign(private_key)
console.log(private_key)
{
"errorMessage": "Invalid state: Not all utxo information is available to sign the transaction.",
"errorType": "bitcore.ErrorInvalidState",
"stackTrace": [
"Error",
"new NodeError (/var/task/node_modules/bitcore-lib-cash/lib/errors/index.js:20:41)",
"Object.checkState (/var/task/node_modules/bitcore-lib-cash/lib/util/preconditions.js:9:13)",
"Transaction.sign (/var/task/node_modules/bitcore-lib-cash/lib/transaction/transaction.js:1077:5)",
"/var/task/src/custody/utils/biputils.js:155:12",
"sign_transaction (/var/task/src/custody/utils/biputils.js:167:6)",
"Object.generate_signature (/var/task/src/custody/assets/bitcoincash.js:220:23)",
"<anonymous>",
"process._tickDomainCallback (internal/process/next_tick.js:228:7)"
]
}
UPDATE
I just checked the source code of bitcore-lib-cash, when calling a toString or toBuffer function, they don't encode every field in input.
Here is one of the part of process to encode input:
Input.prototype.toBufferWriter = function(writer) {
if (!writer) {
writer = new BufferWriter();
}
writer.writeReverse(this.prevTxId);
writer.writeUInt32LE(this.outputIndex);
var script = this._scriptBuffer;
writer.writeVarintNum(script.length);
writer.write(script);
writer.writeUInt32LE(this.sequenceNumber);
return writer;
};
So I think you have to rewrite this toBufferWriter function or parse every field in the txhex and rebuild the transaction again.
Your txhex is invalid.
After decode txhex, it should have a output field in each UTXO input object, that's where the error came from.
I'm trying to get a value from an API and usually I get it through a list and just use an index and the String to get the info I need (e.g. data[index]["String"]), however this API sends a Map<String, dynamic> and I used the key to retrieve part of the Map (data["key"]}) but I am trying to be more specific in the value. Is there a way to get the exact value, like data["key"]["String"]?
You can use json.decode on your data
Example :
var response = await /* httpcall */
var data = json.decode(response.body);
Depending on the structure of your response you might have to change the field that you json encode, but at least you can now use data['foo']['bar']
I'm using Google's Flatbuffer. I've created a simple schema for C++ that just takes a name and ID as the fields. After creating the auto generated code and running the fields through the CreateDetails() function, how would I get the bytearray to pass into ActiveMQ? I've searched around but couldn't find much about the byte array.
My schema:
table details {
name:string;
id: int;
};
root_type details;
My .cpp application:
auto name = builder.CreateString("some text here");
auto id = 25;
auto detail = CreateDetails(builder, name, id);
builder.Finish(detail);
Now, from my understanding, the sample message should be serialized, but I'm not sure how to grab the serialized data as a byte array. I was able to access the root and just go down the tree and look at the data, but I want to grab the entire message as a bytearray.
Please and thank you!
builder.GetBufferPointer()
builder.GetSize()
I'm a new User of POCO and could get HTTP response after HTTP::Request.
By the way, How do I create HTTP request with some parameters? For example, I want to set URI, http://xxxx/index.html?name=hoge&id=fuga&data=foo.
Of course I know it's possible if I set this uri directly. But I want to realize this like below. Does anyone know this way?
URI uri("http://xxx/index.html");
uri.setParam("name", "hoge");
uri.setParam("id", "fuga");
uri.setParam("data", "foo");
If you had looked up the documentation for Poco::URI, you'd see it's done with uri.addQueryParameter("name", "value"):
void addQueryParameter(
const std::string & param,
const std::string & val = ""
);
Adds "param=val" to the query; "param" may not be empty. If val is empty, only '=' is appended to the parameter.
In addition to regular encoding, function also encodes '&' and '=', if found in param or val.
You can also set all the parameters with setQueryParameters.
Unfortunately, Poco doesn't let you set the value of an existing query parameter (or remove it). If you want to do that, you have to clear the query portion of the URI and readd all the parameters you want with their values.
Let's start by saying I have a very large project, part of this project is to grab a user recovery action status, and a user email, and send it through a service layer back to the front end of the application. The catch is, the email needs to be altered on the back end so it doesn't get sent plain text. What I mean by this is, when the value gets populated on the back end, I need to have some code to modify it so it will have a format like this: j*****e#domain.com. This absolutely needs to be done in the method that I'm working on(which honestly isn't very big). Here is the method I have that will grab the status from another method within the same class, as well as grabbing the email of the user:
public CredentialRecoveryResponse RecoveryResponse(CredentialRecoveryRequest request)
{
CredentialRecoveryResponse response = new CredentialRecoveryResponse();
response.Status = RecoverCredentials(request);
if (response.Status == UserRecoveryActionStatus.Success)
{
User usr = UserRepository.GetByID(request.UserID);
response.Email = usr.EmailAddress;
}
return response;
}
Somehow, inside this method, I need to take that usr.EmailAddress and modify it do "block" or change the values to "*" for all characters except the first and last characters before the "#domain.com" portion. Is there a quick and easy way to do this within the method that way the whole email address isn't getting sent back through the wire?
Here's one take:
private static string ObfuscateEmail(string email)
{
return Regex.Replace(email, "^(?<name>[^#]+)", m => {
string match = m.Groups["name"].Value;
return match[0] + new String('*', match.Length - 1);
});
}
What is this doing?
The method uses Regex.Replace and passes a lambda function to do the actual replacement
The regex pattern simply says match everything to the left of the # sign and create a named group called 'name'.
The lambda function then takes the first character of the match and appends to it a series of asterisks, using an overload of the String method (char, int) which repeats that char N number of times. It's N-1 here since the first char is unobfuscated.