Can't attach a message for transaction in Waves bitcoin by package #waves/waves-transactions - attachment

I try to create transaction on Testnet Waves blockchain with short message, I use attachment as a string according to documentation, but I receive a error, that attachment is Object. I see in result of "transfer" function that attachment is not a string it is object: { type: 'string', value: '2XTb5rrCf5d1zJkj2jZGjQaA4NPV' }, but I can't do anything with that, and in the end i have the same error.
P.s.: without attachment this part of code is work fine.
const { transfer, broadcast } = require("#waves/waves-transactions");
const nodeUrl = "https://nodes-testnet.wavesnodes.com";
const privateKey = "...realPrivateKey...";
const signedTranserTx = transfer(
{
amount: 1,
recipient: "3MqfoN68Gj3Eqc9C7pHLqbYvd5k2hovSkgi",
attachment: "2XTb5rrCf5d1zJkj2jZGjQaA4NPV"
}
, {privateKey: privateKey}
);
broadcast( signedTranserTx, nodeUrl)
.then(resp => console.log(resp))
.catch(err => console.error(err));
Output of signedTranserTx =
{
type: 4,
version: 3,
senderPublicKey: 'He58mC5hQHjQtx6sKcq7MVaeTc6Je9wJthp2P8m7fUXU',
assetId: null,
recipient: '3MqfoN68Gj3Eqc9C7pHLqbYvd5k2hovSkgi',
amount: 1,
**attachment: { type: 'string', value: '2XTb5rrCf5d1zJkj2jZGjQaA4NPV' },**
fee: 100000,
feeAssetId: null,
timestamp: 1602355529316,
proofs: [
'fLmLYr2D1YMLogLtne4NW4YUiB6GufqsfmEjWGqeGS7R56DrB9mXGYDsfQngMGV3EPDwgsh5zNgiv971KezF5AG'
],
chainId: 84,
id: 'Hw55x7FTuYsPUtuczrdRaJ2kqDCVUgxPuoxndajmeC3C'
}
Error request:
{
error: 1,
message: 'failed to parse json message',
cause: null,
validationErrors: { 'obj.attachment': [ [Object] ] }
}

i add type and version attribute to transaction, but change version of transaction from 3 to 2 and now its work. But i didn`t find any information about in documentation.
const signedTranserTx = transfer(
{
type: 4,
version: 2,
amount: 10000,
recipient: "3MqfoN68Gj3Eqc9C7pHLqbYvd5k2hovSkgi",
attachment: codedAttachment
}
, {privateKey: privateKey}
);

Related

Add metadata from projection

given following projection:
options({
$includeLinks: false,
reorderEvents: false,
processingLag: 0
});
fromCategory('my_events')
.partitionBy(({ data }) => data.Id)
.when({
$init: () => {
return {
data: {
Id: null,
Version: 0,
Key: null,
Title: null
}
};
},
ItemAdded: (state, { data }) => {
state.data = {
Version: state.data.Version + 1,
...data
};
How can I write specific metadata to the output stream item_state-{0}? I'd basically like to avoid putting the relevant stuff to the state as I also want to directly process events on client side, where I have the required info in metadata.

How can I display multiple ResponseDTOs' schemas in Swagger/NestJS?

I have this route which can return one of these two different DTOs:
#Get()
#ApiQuery({ name: 'legacy', description: "'Y' to get houses legacy" })
async findAllHouses(
#Query('legacy') legacy: string,
): Promise<HousesDto[] | HousesLegacyDto[]> {
...
}
I want to display both of these ResponseDTOs in swagger.
I've tried this decorator:
#ApiOkResponse({
schema: { oneOf: refs(HousesDto, HousesLegacyDto) },
})
// OR
#ApiOkResponse({
schema: {
oneOf: [
{ $ref: getSchemaPath(HousesDto) },
{ $ref: getSchemaPath(HousesLegacyDto) },
],
},
})
with #ApiExtraModels() on top of DTO classes and #ApiProperty() on each properties.
But I still get empty objects in Swagger and I suppose it would not have even taken array types in consideration.
How can I display both of these schemas properly?
Seems to me like a lot of very obscure solutions have been posted here and there, so I will try to clarify what needs to be done.
You have two DTOs:
export class SomeStatusDto {
#ApiProperty({
description: 'Id',
example: 1,
})
#IsNumber()
id: number;
#ApiProperty({
description: 'Status',
example: 'in_progress',
})
#IsString()
status: string;
}
export class ErrorStatusDto {
#ApiProperty({
description: 'Id',
example: 1,
})
#IsNumber()
id: number;
#ApiProperty({
description: 'Error',
example: 'Some error string',
})
#IsString()
error: string;
}
Then you have your controller:
#UseGuards(AccountTypesGuard)
#ApiOperation({ summary: 'Get status of...' })
#Get('status')
#ApiExtraModels(SomeStatusDto, ErrorStatusDto)
#ApiOkResponse({
schema: { anyOf: refs(SomeStatusDto, ErrorStatusDto) },
})
async getPullStatus(
#Request() req,
#Param('id', ParseIntPipe) someId: number,
): Promise<SomeStatusDto | ErrorStatusDto> {
// check if someId belongs to user
const idBelongsToUser = await this.myService.validateSomeId(
req.user.id,
someId,
);
if (!idBelongsToUser) {
throw new ForbiddenException(
`SomeId does not belong to user (someId=${someId}, userId=${req.user.id})`,
);
}
const key = `status-${someId}`;
const response = await this.redisService.getByKey(key);
return response ? response : {};
}
Note the solution below. You need to reference the DTOs as #ApiExtraModels() and then you can add them as anyOf: refs(...) in your schema.
#ApiExtraModels(SomeStatusDto, ErrorStatusDto)
#ApiOkResponse({
schema: { anyOf: refs(SomeStatusDto, ErrorStatusDto) },
})
Hope this helps somebody :)
so I encountered a similar issue and this is how you could get the output shown in the image above.
Using the #ApiResponse decorator you could set the two responses using the examples property, try the code sample below
#ApiResponse({
status: 200,
description: 'Successful response',
content: {
'application/json': {
examples: {
HousesDto: { value: HousesDto },
HousesLegacyDto: { value: HousesLegacyDto },
},
},
},
})

unexpected error when trying stripe with apple pay using ionic capacitor

i am using https://github.com/capacitor-community/stripe to integrate in my ionic-angular app with apple pay.
the payload and code looks like below
const Stripe = Plugins.Stripe as StripePlugin;
Stripe.setPublishableKey({ key: 'xxxx' }); //test key
const clientSecret: string = 'xxxx'; //test secret
pay(){
await Stripe.confirmPaymentIntent({
clientSecret,
applePayOptions: {
// options here
merchantId: 'merchant.xxx.xxx',
country: 'US',
currency: 'USD',
items: [
{
label: 'my desc',
amount: 1, // amount in dollars
}
]
},
})
}
this shows the apple pay sheeet nicely but when i double click to confirm the payment it thorws error that i can see in the xcode console as below
ERROR MESSAGE: {"message":"payment failed: There was an unexpected error -- try again in a few seconds","errorMessage":"There was an unexpected error -- try again in a few seconds"}
i have tried it on device and with live keys as well but no luck
The code below worked for me.
Note that it is 1 for $1 but stripe uses 100 for $1.
try {
const paymentIntent = await this.stripeService.createPaymentIntentOnServer(100);
const result = await StripePlg.confirmPaymentIntent(
{ clientSecret: paymentIntent.client_secret,
applePayOptions: {
merchantId: 'merchant.app.myapp',
items: [{ label: 'Bread sticks', amount: 1, },],
currency: 'NZD',
country: 'NZ',
},
});
// then call finalizeApplePayTransaction with the result to dismiss the UI modal
StripePlg.finalizeApplePayTransaction({ success: true });
} catch (err) {
console.log(err);
StripePlg.finalizeApplePayTransaction({ success: false })
}
// Server
// createPaymentIntentOnServer - this returns the client_secret
const paymentIntent = await stripe.paymentIntents.create({
amount: paymentAmount, // 100
currency: 'nzd',
payment_method_types: ['card'],
customer: customer.id, // I use a Stripe Customer here which I create first
expand: ['invoice']
});
Stripe allows only integer as amount (1 = 1cent) so 0.5$ would be 50, and 1$ is 100.
const Stripe = Plugins.Stripe as StripePlugin;
Stripe.setPublishableKey({ key: 'xxxx' }); //test key
const clientSecret: string = 'xxxx'; //test secret
pay(){
await Stripe.confirmPaymentIntent({
clientSecret,
applePayOptions: {
// options here
merchantId: 'merchant.xxx.xxx',
country: 'US',
currency: 'USD',
items: [
{
label: 'my desc',
amount: 50, // amount in cents
}
]
},
})
}

Exporting Swagger/OpenAPI to Postman collection with examples

I have a large codebase in NestJS for which I have used Swagger to document the API routes ("#nestjs/swagger": "^3.1.0"). However, the Swagger UI seems to be underpowered for such large projects and I would like to migrate to Postman. Here is what happens:
Take for example this model structure:
export class IApiGenericRequest {
#ApiModelProperty({
example: null,
default: 0
})
appVersionCode: number;
#ApiModelProperty({
example: false,
default: false
})
testerMode: boolean;
#ApiModelProperty({
example: 1,
default: 1
})
appId: number;
}
export class IApiGenericRequestUserId extends IApiGenericRequest {
#ApiModelProperty({
example: 1,
default: 1
})
userId: number;
}
class IApiEventsV2UserDetails extends IApiGenericRequestUserId {
#ApiModelProperty({
example: 1
})
eventId: number;
#ApiModelProperty({
example: false
})
loadMap: boolean;
}
Example route:
#Post('details')
#ApiResponse({
status: 200,
description: 'Get event user details',
type: null
})
async details(#Res() res: Response, #Body() body: IApiEventsV2UserDetails) {
// call service
}
In Swagger UI the request example is shown properly:
{
"appVersionCode": null,
"testerMode": false,
"appId": 1,
"userId": 25,
"eventId": 5,
"loadMap": false
}
When imported in Postman it looks like this:
{
"appVersionCode": "<number>",
"testerMode": "<boolean>",
"appId": 1,
"userId": 25,
"eventId": "<number>",
"loadMap": "<boolean>"
}
I can't figure out what happens here and how can it be fixed.

Google Cloud Print Node API TICKET not working

This is my code and I am using npm node-gcp and sadly, the ticket is not working, I tried to make the copies = 3 to see if the printer will print 3 and to see if the ticket is working or not, But it's not working :(
I tried all the resources i can find, php ticket, c# ticket, But all are not working,
I am inside the code of npm node-gcp and I am trying to modify its code and see what will work and not, because the original code is he is not passing any ticket.
return preq({
method: "POST",
uri: "https://www.google.com/cloudprint/submit",
form: {
title: "Print job title",
content:
"test print",
ticket: {
version: "1.0",
print: {
copies: {
copies: 3
},
page_orientation: {
type: 0
},
margins: {
top_microns: 0,
bottom_microns: 0,
left_microns: 0,
right_microns: 0
}
}
},
contentType: "url", //optional, default = url
printerid: xxxxxxxxxxxxx,
tags: ["tag1", "tag2"] //optional, default = [],
},
headers: {
"X-CloudPrint-Proxy": "node-gcp",
Authorization: "OAuth " + this.options.accessToken
},
json: true
})
.then(function(result) {
return result;
})
.nodeify(cb);
});
i am expecting a response of number of pages is 3 but all I am getting is 1 piece of paper.
I just had to deal with this issue and discovered that ticket needs to be sent as a stringified json object.
For form, try this instead:
form: {
title: "Print job title",
content:
"test print",
ticket: JSON.stringify({
version: "1.0",
print: {
copies: {
copies: 3
},
page_orientation: {
type: 0
},
margins: {
top_microns: 0,
bottom_microns: 0,
left_microns: 0,
right_microns: 0
}
})
},

Resources