Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NFToken, Clawback & AMM #52

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
159 changes: 84 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,27 @@ and the examples below.
The XRP wallet app comes with the following features:

- Support for all transaction types:
- AMMBid
- AMMCreate
- AMMDelete
- AMMDeposit
- AMMVote
- AMMWithdrawal
- AccountSet
- AccountDelete
- CheckCancel
- CheckCash
- CheckCreate
- Clawback
- DepositPreauth
- EscrowCancel
- EscrowCreate
- EscrowFinish
- NFTokenAcceptOffer
- NFTokenBurn
- NFTokenCancelOffer
- NFTokenCreateOffer
- NFTokenMint
- OfferCancel
- OfferCreate
- Payment
Expand All @@ -36,6 +48,8 @@ The XRP wallet app comes with the following features:
- PaymentChannelFund
- SetRegularKey
- SignerListSet
- TicketCancel
- TicketCreate
- TrustSet
- Support for all transaction common fields such as memos
- Support for issued assets such as SOLO, stocks and ETFs
Expand Down Expand Up @@ -93,50 +107,49 @@ An example of a basic payment transaction using this library is shown below:
import Transport from "@ledgerhq/hw-transport-node-hid";
// import Transport from "@ledgerhq/hw-transport-u2f"; // for browser
import Xrp from "@ledgerhq/hw-app-xrp";
import { encode } from 'ripple-binary-codec';
import { encode } from "ripple-binary-codec";

function establishConnection() {
return Transport.create()
.then(transport => new Xrp(transport));
return Transport.create().then((transport) => new Xrp(transport));
}

function fetchAddress(xrp) {
return xrp.getAddress("44'/144'/0'/0/0").then(deviceData => {
return {
xrp,
address: deviceData.address,
publicKey: deviceData.publicKey.toUpperCase()
}
});
return xrp.getAddress("44'/144'/0'/0/0").then((deviceData) => {
return {
xrp,
address: deviceData.address,
publicKey: deviceData.publicKey.toUpperCase(),
};
});
}

function signTransaction(context, transaction) {
const preparedTransaction = {
Account: context.address,
SigningPubKey: context.publicKey,
...transaction
};
const preparedTransaction = {
Account: context.address,
SigningPubKey: context.publicKey,
...transaction,
};

const transactionBlob = encode(preparedTransaction);
const transactionBlob = encode(preparedTransaction);

console.log('Sending transaction to device for approval...');
return context.xrp.signTransaction("44'/144'/0'/0/0", transactionBlob);
console.log("Sending transaction to device for approval...");
return context.xrp.signTransaction("44'/144'/0'/0/0", transactionBlob);
}

const transactionJSON = {
TransactionType: "Payment",
Destination: "rTooLkitCksh5mQa67eaa2JaWHDBnHkpy",
Amount: "1000000",
Fee: "15",
Flags: 2147483648,
Sequence: 57,
TransactionType: "Payment",
Destination: "rTooLkitCksh5mQa67eaa2JaWHDBnHkpy",
Amount: "1000000",
Fee: "15",
Flags: 2147483648,
Sequence: 57,
};

establishConnection()
.then(xrp => fetchAddress(xrp))
.then(context => signTransaction(context, transactionJSON))
.then(signature => console.log(`Signature: ${signature}`))
.catch(e => console.log(`An error occurred (${e.message})`));
.then((xrp) => fetchAddress(xrp))
.then((context) => signTransaction(context, transactionJSON))
.then((signature) => console.log(`Signature: ${signature}`))
.catch((e) => console.log(`An error occurred (${e.message})`));
```

### Advanced Usage
Expand All @@ -151,64 +164,60 @@ with a signature of the Ledger device is shown below (uses imports and functions

```javascript
const transactionJSON = {
Account: "r4PCuDkjuV2e23xVP8ChkVxo1aG2Ufpkjb",
TransactionType: "Payment",
Destination: "rTooLkitCksh5mQa67eaa2JaWHDBnHkpy",
Amount: "1000000",
Fee: "15",
Flags: 2147483648,
Sequence: 47,
SigningPubKey: "" // Must be blank
Account: "r4PCuDkjuV2e23xVP8ChkVxo1aG2Ufpkjb",
TransactionType: "Payment",
Destination: "rTooLkitCksh5mQa67eaa2JaWHDBnHkpy",
Amount: "1000000",
Fee: "15",
Flags: 2147483648,
Sequence: 47,
SigningPubKey: "", // Must be blank
};

// Sourced externally from other signing parties, replace "..." with actual values.
const otherSigners = [
{
Signer: {
Account: "...",
SigningPubKey: "...",
TxnSignature: "..."
}
{
Signer: {
Account: "...",
SigningPubKey: "...",
TxnSignature: "...",
},
{
Signer: {
Account: "...",
SigningPubKey: "...",
TxnSignature: "..."
}
}
},
{
Signer: {
Account: "...",
SigningPubKey: "...",
TxnSignature: "...",
},
},
];

function retrieveSignerData(transaction) {
return establishConnection()
.then(xrp => fetchAddress(xrp))
.then(context => {
return signTransaction(context, transaction)
.then(signature => {
return {
Signer: {
Account: context.account,
SigningPubKey: context.publicKey,
TxnSignature: signature.toUpperCase()
}
}
});
})
.catch(e => console.log(`An error occurred (${e.message})`));
return establishConnection()
.then((xrp) => fetchAddress(xrp))
.then((context) => {
return signTransaction(context, transaction).then((signature) => {
return {
Signer: {
Account: context.account,
SigningPubKey: context.publicKey,
TxnSignature: signature.toUpperCase(),
},
};
});
})
.catch((e) => console.log(`An error occurred (${e.message})`));
}

retrieveSignerData(transactionJSON)
.then(signer => {
return {
...transactionJSON,
Signers: [
...otherSigners,
signer
]
}
})
.then(transaction => console.log(transaction))
.catch(e => console.log(`An error occurred (${e.message})`));
.then((signer) => {
return {
...transactionJSON,
Signers: [...otherSigners, signer],
};
})
.then((transaction) => console.log(transaction))
.catch((e) => console.log(`An error occurred (${e.message})`));
```

### Additional Notes
Expand Down
2 changes: 1 addition & 1 deletion src/xrp/amount.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static int format_xrp(uint64_t amount, field_value_t *dst) {
return 0;
}

static bool is_all_zeros(const uint8_t *data, uint8_t length) {
bool is_all_zeros(const uint8_t *data, uint8_t length) {
for (size_t i = 0; i < length; ++i) {
if (data[i] != 0) {
return false;
Expand Down
1 change: 1 addition & 0 deletions src/xrp/amount.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void amount_formatter(field_t* field, field_value_t* dst);
void currency_formatter(field_t* field, field_value_t* dst);

bool has_non_standard_currency(field_t* field);
bool is_all_zeros(const uint8_t *data, uint8_t length);

#define XRP_AMOUNT_LEN 8
#define ISSUED_CURRENCY_LEN 48
Expand Down
Loading
Loading