-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(anchor): move together island & ship dirs into
anchor
- Loading branch information
Wildan
committed
Jun 21, 2019
1 parent
55b6997
commit 033ab55
Showing
32 changed files
with
7,190 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,3 @@ | ||
# Anchor proto | ||
|
||
## Anchor object schema | ||
|
||
| Name | Description | | ||
| ---------------------- | -------------------------------------------------- | | ||
| description (optional) | Generic identifier | | ||
| version | Anchor schema version | | ||
| target | Target island type. One of `nem`, `btc`, or `eth` | | ||
| locks | Array of `Lock` objects. ***Minimum length of 1*** | | ||
|
||
## Lock object schema | ||
|
||
| Name | Description | | ||
| ---------------------------- | ----------------------------------------------------------- | | ||
| type | Ship type. One of `nem` or `eth` | | ||
| version (optional) | Current version of ship. Eg. NEM catapult will be `0.2.0.2` | | ||
| name (optional) | Ship identifier | | ||
| block | Object containing ship's data | | ||
| lastKnownPosition (optional) | Transaction hash of the last anchor point to an island | | ||
|
||
## Block object schema | ||
|
||
| Name | Description | | ||
| -------------- | ------------------------------------------------------------ | | ||
| height | Current block height | | ||
| hash | Block hash at current height | | ||
| timestamp | Timestamp at current height | | ||
| uri (optional) | Array of uri's to check the validity of the block. It should provide a direct link to the block resource | | ||
|
||
### Example anchor message in JSON format | ||
|
||
```json | ||
{ | ||
"description": "LuxTag Chain Anchoring Service", | ||
"version": "1.0.0", | ||
"target": "eth", | ||
"locks": [ | ||
{ | ||
"type": "nem", | ||
"version": "0.2.0.2", | ||
"name": "LuxTag Private Chain X", | ||
"block": { | ||
"height": 1, | ||
"hash": "FAD4265E038881BC9772E69A…DD4FF86F191FD5F8C3AD566", | ||
"timestamp": 0, | ||
"uri": [ | ||
"http://localhost:3000/block/1" | ||
] | ||
}, | ||
"lastKnownPosition": "" | ||
}, | ||
... Anchor multiple private chains at once | ||
] | ||
} | ||
``` | ||
Example: | ||
- curl https://cas-shipper.luxtagofficial.now.sh/bcm::iium | ||
- curl https://cas-shipper.luxtagofficial.now.sh/bcm::nem |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"bcm::iium": { | ||
"ship": { | ||
"type": "NEM2", | ||
"endpoint": "http://api.bcm.luxtag.io", | ||
"networkType": "MIJIN_TEST" | ||
}, | ||
"island": { | ||
"type": "NEM2", | ||
"endpoint": "https://api.iium.luxtag.io", | ||
"networkType": "MIJIN_TEST", | ||
"privateKey": "some-private-key" | ||
} | ||
}, | ||
"bcm::nem": { | ||
"ship": { | ||
"type": "NEM2", | ||
"endpoint": "https://api.bcm.luxtag.io", | ||
"networkType": "MIJIN_TEST" | ||
}, | ||
"island": { | ||
"type": "NEM", | ||
"endpoint": "http://bigalice2.nem.ninja:7890", | ||
"networkType": "testnet", | ||
"privateKey": "some-private-key" | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import fetch from 'node-fetch'; | ||
import { parse } from 'url'; | ||
import * as services from '../../_proto/anchor_grpc_pb'; | ||
import * as messages from '../../_proto/anchor_pb'; | ||
import { | ||
Account, | ||
Deadline, | ||
AccountHttp, | ||
NetworkType, | ||
TransactionHttp, | ||
PlainMessage, | ||
TransferTransaction, | ||
} from 'nem2-sdk'; | ||
|
||
export interface IIslandArgs { | ||
endpoint: string; | ||
networkType: string; | ||
privateKey: string; | ||
} | ||
|
||
export class Island { | ||
private args: IIslandArgs; | ||
private hostname: string; | ||
private port: string; | ||
|
||
public constructor(args: IIslandArgs) { | ||
this.args = args; | ||
|
||
const { protocol, hostname, port } = parse(this.args.endpoint) | ||
this.hostname = protocol + '//' + hostname | ||
this.port = port | ||
} | ||
|
||
public location(call, callback) { | ||
const reply = new messages.CallSign(); | ||
const anchor = this.generateAnchor(call.request); | ||
this.announceAnchor(anchor).then((response) => { | ||
console.log(response); | ||
reply.setId(response.hash); | ||
callback(null, reply); | ||
}); | ||
} | ||
|
||
public generateAnchor(lock: messages.Lock): messages.Anchor { | ||
const anchor = new messages.Anchor(); | ||
anchor.setDescription('LuxTag Chain Anchoring Service'); | ||
anchor.setVersion('1.0.2'); | ||
anchor.setTarget(messages.IslandType.NEM2); | ||
anchor.addLocks(lock); | ||
return anchor; | ||
} | ||
|
||
public async announceAnchor(anchor: messages.Anchor): Promise<any> { | ||
const sender = Account.createFromPrivateKey(this.args.privateKey, NetworkType[this.args.networkType]); | ||
const accountHttp = new AccountHttp(this.args.endpoint); | ||
const transactionHttp = new TransactionHttp(this.args.endpoint); | ||
|
||
const serialized = anchor.serializeBinary(); | ||
|
||
// let msg = Buffer.from(serialized).toString('utf8') | ||
// console.log("msg:", msg) | ||
// // fix "Error: hex string has unexpected size '285'" | ||
// msg += '\u001a\f101645436340' | ||
|
||
const msg = 'hello' | ||
|
||
const recipientAddress = sender.address | ||
const transferTransaction = TransferTransaction.create( | ||
Deadline.create(), | ||
recipientAddress, | ||
[], | ||
PlainMessage.create(msg), | ||
NetworkType.MIJIN_TEST); | ||
|
||
const signedTx = sender.sign(transferTransaction) | ||
return transactionHttp.announce(signedTx) | ||
.toPromise() | ||
.then(() => ({ | ||
hash: signedTx.hash | ||
})) | ||
} | ||
|
||
public currentBlockHeight(): Promise<string> { | ||
return fetch(this.args.endpoint + '/diagnostic/storage') | ||
.then(resp => resp.json()) | ||
.then(json => json.numBlocks.toString()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"dependencies": { | ||
"nem-sdk": "^1.6.7", | ||
"nem2-sdk": "^0.11.6", | ||
"node-fetch": "^2.6.0" | ||
} | ||
} |
Oops, something went wrong.