Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
357cc26
Add flow starport initial version
toninorair May 26, 2021
fd083db
Delete useless files
toninorair May 26, 2021
9386815
Clean up README a little bit
toninorair May 26, 2021
4080f40
Fix README [skip ci]
toninorair May 26, 2021
e5369a0
Add more tests for invalid notices [skip ci]
toninorair May 27, 2021
1bc891c
Refactor code to delete copy-paste [skip ci]
toninorair May 27, 2021
61d1ca0
Merge branch 'toni/init-flow' of https://github.com/compound-finance/…
toninorair May 27, 2021
e34a6b0
Readability fix
toninorair May 27, 2021
55b4397
Readability fixes for Starport
toninorair Jun 1, 2021
7f8fdfb
Add flow javascript signing instead of hardcoding it
toninorair Jun 2, 2021
84f1932
Get rid of all hardcoded signatures
toninorair Jun 2, 2021
c64be75
Replace ECDSA_P256 with ECDSA_Secp256k1
toninorair Jun 3, 2021
c0dd349
Use testnet addresses instead of emulator
toninorair Jun 7, 2021
cfaaaa8
Add some fcl transactions here
toninorair Jun 7, 2021
cdd7540
Add Go web server for fetching events
toninorair Jun 14, 2021
666582e
Add helpers and clean-ups for Go server
toninorair Jun 14, 2021
a4365d4
Clean up events
toninorair Jun 14, 2021
93a05fd
Add flow blocks processing
toninorair Jun 14, 2021
25d86b8
Merge branch 'develop' into toni/init-flow
toninorair Jun 15, 2021
0db80a8
Add initial version of Flow client
toninorair Jun 17, 2021
def08dd
Modify events/blocks responses to match gateway Flow client
toninorair Jun 18, 2021
2539ad4
Update all dependencies, make everything back to work
toninorair Jun 29, 2021
00c22fe
Revert "Update all dependencies, make everything back to work"
toninorair Jun 30, 2021
6873202
Gateway Flow Full Support - Part 2 (#391)
toninorair Jul 7, 2021
a2c98bb
Merge branch 'toni/init-flow' of https://github.com/compound-finance/…
toninorair Jul 21, 2021
8c4753a
Revert "Revert "Update all dependencies, make everything back to work""
toninorair Jul 22, 2021
5f72ff5
Check that everything works, delete some comments
toninorair Jul 23, 2021
ddbbae2
Revert useless changes in integration tests, got there by mistake
toninorair Jul 27, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ members = [
'our-std',
'gateway-crypto',
'ethereum-client',
'flow-client',
'test-utils/open-oracle-mock-reporter',
'trx-request',
'types-derive',
Expand Down
38 changes: 38 additions & 0 deletions flow-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
name = 'flow-client'
version = '0.1.0'
authors = ['Compound <https://compound.finance>']
edition = '2018'

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
codec = { package = 'parity-scale-codec', version = '2.0.0', default-features = false, features = ['derive'] }
hex = { version = '0.4.2', default-features = false }
hex-buffer-serde = { version = "0.3.0", default-features = false, features = ['alloc', 'const_len'] }
serde = { version = '1.0.125', features = ['derive'], default-features = false }
serde_json = { version = '1.0.64', features = ['alloc'], default-features = false }
sp-io = { default-features = false, features = ['disable_oom', 'disable_panic_handler'], git = 'https://github.com/compound-finance/substrate', branch = 'jflatow/compound'}
sp-core = { default-features = false, git = 'https://github.com/compound-finance/substrate', branch = 'jflatow/compound' }
sp-runtime = { default-features = false, git = 'https://github.com/compound-finance/substrate', branch = 'jflatow/compound' }
sp-runtime-interface = { default-features = false, git = 'https://github.com/compound-finance/substrate', branch = 'jflatow/compound' }
sp-std = { default-features = false, git = 'https://github.com/compound-finance/substrate', branch = 'jflatow/compound' }
our-std = { path = '../our-std', default-features = false }
types-derive = { path = '../types-derive' }
gateway-crypto = { path = '../gateway-crypto', default-features = false }

[features]
default = ['std']
std = [
'codec/std',
'serde/std',
'serde_json/std',
'sp-core/std',
'sp-io/std',
'sp-runtime/std',
'sp-runtime-interface/std',
'sp-std/std',
'our-std/std',
'gateway-crypto/std',
]
runtime-debug = ['our-std/runtime-debug']
74 changes: 74 additions & 0 deletions flow-client/src/events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
use codec::{Decode, Encode};
use our_std::convert::TryInto;
use our_std::{Deserialize, RuntimeDebug, Serialize};

use types_derive::Types;

#[derive(Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug, Types, Serialize, Deserialize)]
struct Lock {
asset: String,
// sender: String,
recipient: String,
amount: u128,
}

#[derive(Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug, Types, Serialize, Deserialize)]
pub enum FlowEvent {
Lock {
asset: [u8; 8],
// sender: String,
recipient: [u8; 8],
amount: u128,
}, // NoticeInvoked {
// era_id: u32,
// era_index: u32,
// notice_hash: [u8; 32],
// result: Vec<u8>,
// }
}

#[derive(Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug)]
pub enum EventError {
UnknownEventTopic(String),
ErrorParsingData,
}

pub fn decode_event(topic: &str, data: &str) -> Result<FlowEvent, EventError> {
match topic {
"Lock" => {
let event_res: serde_json::error::Result<Lock> = serde_json::from_str(&data);
let event = event_res.map_err(|_| EventError::ErrorParsingData)?;
let asset_res = gateway_crypto::flow_asset_str_to_address(&event.asset);

Ok(FlowEvent::Lock {
asset: asset_res.ok_or(EventError::ErrorParsingData)?,
// sender: event.sender,
recipient: hex::decode(event.recipient)
.map_err(|_| EventError::ErrorParsingData)?
.try_into()
.map_err(|_| EventError::ErrorParsingData)?,
amount: event.amount,
})
}
_ => Err(EventError::UnknownEventTopic(topic.to_string())),
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_flow_decode_lock_event() {
let topic = "Lock";
let data = "{\"asset\":\"FLOW\",\"recipient\":\"fc6346ab93540e97\",\"amount\":1000000000}";
assert_eq!(
decode_event(topic, data),
Ok(FlowEvent::Lock {
asset: [70, 76, 79, 87, 0, 0, 0, 0], // "FLOW" asset
recipient: hex::decode("fc6346ab93540e97").unwrap().try_into().unwrap(),
amount: 1000000000
})
)
}
}
Loading