mirror of
				https://github.com/hackku21/loc-chain-app.git
				synced 2025-06-13 12:54:05 +00:00 
			
		
		
		
	fix p2p transactions
This commit is contained in:
		
							parent
							
								
									68f06e5f05
								
							
						
					
					
						commit
						dbc0f84d58
					
				| @ -42,13 +42,15 @@ class Connect { | ||||
|         _userName, | ||||
|         strategy, | ||||
|         onConnectionInitiated: onConnectionInit, | ||||
|         onConnectionResult: (String id, Status status) { | ||||
|         onConnectionResult: (String id, Status status) async { | ||||
|           // Called when connection is accepted/rejected | ||||
|           // if connection is accepted send the transaction | ||||
|           endpointMap.forEach((key, value) async { | ||||
|             String str = await Transaction.generateHash(key); | ||||
|             Nearby().sendBytesPayload(key, Uint8List.fromList(str.codeUnits)); | ||||
|           }); | ||||
|           if (status != Status.CONNECTED) { | ||||
|             return; | ||||
|           } | ||||
|           // Connected to other device, send combined hash and pub key | ||||
|           String str = await Transaction.generateHash(id); | ||||
|           Nearby().sendBytesPayload(id, Uint8List.fromList(str.codeUnits)); | ||||
|         }, | ||||
|         onDisconnected: (String id) { | ||||
|           // Callled whenever a discoverer disconnects from advertiser | ||||
| @ -69,8 +71,15 @@ class Connect { | ||||
|             userName, | ||||
|             id, | ||||
|             onConnectionInitiated: onConnectionInit, | ||||
|             onConnectionResult: (id, status) { | ||||
|               showSnackbar(status); | ||||
|             onConnectionResult: (String id, Status status) async { | ||||
|               // Called when connection is accepted/rejected | ||||
|               // if connection is accepted send the transaction | ||||
|               if (status != Status.CONNECTED) { | ||||
|                 return; | ||||
|               } | ||||
|               // Connected to other device, send combined hash and pub key | ||||
|               String str = await Transaction.generateHash(id); | ||||
|               Nearby().sendBytesPayload(id, Uint8List.fromList(str.codeUnits)); | ||||
|             }, | ||||
|             onDisconnected: (id) { | ||||
|               endpointMap.remove(id); | ||||
| @ -114,8 +123,9 @@ class Connect { | ||||
|         transactionMap[_otherId] = | ||||
|             Transaction(hash: combinedHash, pubKey: publicKey); | ||||
|         // sign combined hash with our private key | ||||
|         showSnackbar('Received $_otherId payload: $combinedHash'); | ||||
|         print('Received $_otherId payload: $combinedHash:$publicKey'); | ||||
|         // upload hash+otherKey to firebase | ||||
|         transactionMap.remove(_otherId); | ||||
|       }, | ||||
|       onPayloadTransferUpdate: (endid, payloadTransferUpdate) { | ||||
|         if (payloadTransferUpdate.status == PayloadStatus.IN_PROGRESS) { | ||||
|  | ||||
| @ -19,8 +19,9 @@ class Transaction { | ||||
|     bool idLess = id.compareTo(otherUserId) < 0; | ||||
|     var lesser = idLess ? id : otherUserId; | ||||
|     var greater = idLess ? otherUserId : id; | ||||
|     return DBCrypt() | ||||
|         .hashpw("$lesser-$greater", KeyFileManager.keyPair.privateKey); | ||||
|     // return DBCrypt() | ||||
|     //     .hashpw("$lesser-$greater", KeyFileManager.keyPair.privateKey); | ||||
|     return "$lesser-$greater"; | ||||
|   } | ||||
| 
 | ||||
|   Future<String> generateP2PPayload(String otherUserId) async => | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user